do the ids of photos remain static assuming no changes to photo? - facebook-graph-api

If my app uses the graph api to retrieve the id of a particular photo, will that id always exist as long as the photo it refers to is not modified/deleted out of the users albums?

Yes, node/object IDs like the photo id in your case are unique and will exist as long as the photo isn't deleted.

Related

Graph API: Posting as contributor to shared albums

Shared albums is a quite new feature of Facebook.
I'm encountering an issue with the Graph API while trying to publish photos to a shared album. The issue is actually related to the ID of the album.
As user A, I create an album getting the ID 1 and I add user B as contributor.
As user B, I can retrieve the album 1 using the Graph API but the "can_upload" flag is set to "false". Which prevents contributor B to upload photos to this album.
When I try to get the album's information as user B using facebook.com, it looks like the album has a different ID than 1, let's call it 2. When I retrieve album information as user B using ID 2 with Graph API, the "can_upload" flag is correctly showing "true".
Apparently the original's album ID is known as a different ID to album contributors. But how can I find out the ID allowing contributors to upload photos to it?
As there seems to be no API call to retrieve the ID (2) of the album to be used while publishing as contributor (user B), this is how one can manage to get it:
As user B (contributor), get the info of the album using its original
ID (1). Make sure to include field "cover_photo" in the request.
Get the info of the cover photo, using its ID retrieved above. Make
sure to include the field "link" in the request. Parse the "link"
field in order to retrieve the value of the parameter "set" which
contains the album ID.
Get the album ID by extracting it from the value above. The format is
something like "a.1234567890" or "a.1234567890.2345678901" where the
contributor's album ID (2) would be 1234567890.

how to get to the post id of shared story with graph api

I get shared story feed with graph api.
In The result I have fields like :
type": "photo",
"status_type": "shared_story",
"object_id": "647332045296931"
the object_id is the photo object.
I need the post_id of that photo.
How can I get the post id with graph api from that point ?
Thanks
Using fql get page_story_id(Please refer to https://developers.facebook.com/docs/reference/fql/photo):
Retrieve the page_story_id details:
Access the exact page at www base facebook using this page_story_id(replace underscore with "/posts/"):
The post_id can get via https://graph.facebook.com/420619404634864/feed too:
Or fql:
Updates:
For video, it is easier compare with photo type to find post_id from object_id.
As you can see on the screenshot, concate page id "155483697799865" and object id "4320084459885" with underscore is equal to post_id "155483697799865_4320084459885":
Let's visit the story page using these post_id(Again, replace underscore with "/posts/"):
To be clarify, what i answer is get original post_id for this object id, not post_id of share status.
For example, i share a video from coca-cola fan page, the object id 12345 get from "me/feed" is same with object id 12345 get from "coca-cola/feed", which point to the same video. However, the post_id is different. My answer is help you to find out original story post_id (coca-cola upload a video), not the shared post_id(xxx Shared coca-cola's video)
Cheers

Shopify Python API - how to search for a product

I have built a django app that is the primary store for my products. From this, I publish products to my Shopify Store. Now my django app knows first when my product goes out of stock.
Question:
What options do I have to search for products using the Python API? Can I search by Title, Variant SKU?
Is storing the generated ID while publish the only means to get a handle on the product later?
I want to do this - so that I can mark the products Out Of stock, in a batch process, for example.
Storing the product's id is the simplest way to get a handle on the product later.
However, the product API shows that you can filter products by vendor, handle, product_type, collection_id, published_status, updated_at, created_at or published_at.
The Using the shopify python API page shows how you can use these filters through keyword arguments to the find class method, e.g. shopify.Product.find(collection_id=841564295) to list products in a specific collection.
YOu can use the official shopify python API to find a product with id:
shopify.Product.exists(product.id) # => True
product = shopify.Product.find(292082188312)
For searching products with the product title, you can use GraphQL API

Django, Tastypie and retrieving the new object data

Im playing a little bit with heavy-client app.
Imagine I have this model:
class Category(models.Model):
name = models.CharField(max_length=30)
color = models.CharField(max_length=9)
Im using knockoutjs (but I guess this is not important). I have a list (observableArray) with categories and I want to create a new category.
I create a new object and I push it to the list. So far so good.
What about saving it on my db? Because I'm using tastypie I can make a POST to '/api/v1/category/' and voilĂ , the new category is on the DB.
Ok, but... I haven't refresh the page, so... if I want to update the new category, how I do it?
I mean, when I retrieve the categories, I can save the ID so I can make a put to '/api/v1/category/id' and save the changes, but... when I create a new category, the DB assign a id to it, but my javascript doesn't know that id yet.
in other words, the workflow is something like:
make a get > push the existing objects (with their ids) on a list > create a new category > push it on the list > save the existing category (the category doesnt have the id on the javacript) > edit the category > How I save the changes?
So, my question is, what's the common path? I thought about sending the category and retrieving the id somehow and assign it to my object on js to be able to modify it later. The problem is that making a POST to the server doesn't return anything.
In the past I did something like that, send the object via post, save it, retrieve it and send it back, on the success method retrieve the id and assign it to the js object.
Thanks!
Tastypie comes with an always_return_data option for Resources.
When always_return_data=True for your Resource, the API always returns the full object event on POST/PUT, so that when you create a new object you can get the created ID on the same request.
You can then just read the response from your AJAX and decode the JSON (i dont know about knockout yet).
see the doc : http://readthedocs.org/docs/django-tastypie/en/latest/resources.html?highlight=always_return_data#always-return-data
Hope this helps

Graph API: Can I make multi-calls at a same time?

In fact, I want to get the cover photo for each user's albums.
So, first I get the albums data:
$albums = $GLOBALS["facebook"]->api("/me/albums",'GET');
Then I retrieve the cover_photo id and ask API to get details about this photo (such as the source)
foreach($albums as $album) {
$data = $GLOBALS["facebook"]->api("/". $album["cover_photo"], 'GET');
}
But this make a lot of calls to the API (one per album) and it's seems that she doesn't like.. Because my application return a timeout error.
Is there another way to do what I want?
Thanks.
You can always use the Batch API, or just use FQL. Something like the below would retrieve the src of all the album covers of the current user:
SELECT src
FROM photo
WHERE pid IN (
SELECT cover_pid
FROM album
WHERE owner = me()
)
You can try it here. Obviously you can choose any field to retrieve from the photo table.