Graph API: Sharing a friend's post on my wall - facebook-graph-api

Using the Graph API, how do I share a friend's post on my own wall ?
I don't want to copy the original post's text and create a new post, becuase I need my friend to see that I shared his post.
The post on my wall should look like this

Sharing a post from the API isn't possible - you can only re-post it using the same information, but it would effectively be a new post and wouldn't say who it was shared from (unless you add it manually in the caption, e.g. Someone shared ... via Someone).

Related

Get Facebook Comments via the Graph Api

Im trying to get Facebook comments using the Graph Api.
I've researched online and found an example that works but there's one thing that about it that I can't find any information about it.
Here's the Example that works:
https://graph.facebook.com/19292868552_118464504835613/comments?access_token=ZZZZZZZ
https://graph.facebook.com/XXXXXXXXXXX_YYYYYYYYYYYYYYY/comments?access_token=ZZZZZZZ
How do I get XXXXXXXXXXX_YYYYYYYYYYYYYYY ?
Is it the UserId concatenated with the Comment Id, is it returned by the Graph Api?
Why is there practicaly no information on this?
In the case of getting a page's post_id you can make a call like this to get the post_id.
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
post_id looks something like this - 5704324444475_570454233326 and is in the id field of each returned post.
To get all comments for a page first you need to make a call to get all your posts and then make a call for each post to get comments.

What is the Facebook Graph API query for this link to a photo?

I'm having good luck using python and the FB graph api to collect reactions, comments from Facebook posts however, I'm having trouble targeting this specific photo link:
https://www.facebook.com/SheShopped/photos/a.432191143458704.110954.428340903843728/1367643623246780/?type=3&theater
Can anyone tell me how to deconstruct this link into a FB graph query?
If you want to look at the comments of this specific photo you just need to extract the id from the link (it's the last segment of the url) which is 1367643623246780. You'll find the comments at 1367643623246780/comments:
If you want to find this picture and others like it, you need to notice the type of picture (it is a 'Timeline Photo'). Looking at the relevant API-Documentation (Open Graph Page Photos) these can be found at 'SheShopped/photos/uploaded':

Creating one-to-one RESTful API relationship

I need to create a one-to-one relationship between a Game and a Site - each game happens in one site. In my database, site is an attribute of the Game object which points to a Site object.
I couldn't find much on the internet about this, these are my ideas:
GET /game/<game_id>/site
Gets a game's site, hiding the site id.
POST /game/<game_id>/site
Creates a game's site, this is only used once when creating the game.
PUT /game/<game_id>/site
Updates a game's site
DELETE /game/<game_id>/site
Deletes a game's site.
But what if someone wants to get a list of all the sites? Should I add a /sites URI and have the get method for the Site object detect whether a game_id has been passed in? Should I also let people access a site by /sites/<site_id> Or should I let the client populate their own list of sites by iterating over all games? Finally, I usually have an 'href' attribute for each object which is a link back to itself. If I went with the above design (incl. the /sites/ URI), do I link to /game/<game_id>/site or /sites/<site_id>? Should there be two places to access the same info?
Am I on the right track? Or is there a better way to model one-to-one relationships in REST?
If it matters, I'm using Flask-RESTful to make my APIs.
Your ideas make a lot of sense.
The big distinction is whether or not a site can exist independently of a game. It sounds like it can. For example, two games may point to the same site.
As far as I understand with RESTful API design, there isn't a problem with exposing the same site resource through both /game/<game_id>/site and through /sites/<side_id>. But REST encourages you to link data through hypermedia.
Exposing the site in two different places could complicate things, since you'd then expect to be able to interact with site objects through both of those URLs.
My recommendation to keep your structure explicit and simple would be:
Have a collection of site resources at /sites
Expose site resources at /site/<site_id>
Use a link object from a game to a site. See Thoughts on RESTful API design by Geert Jansen.
Following the link object design, your game resource representation would include something like this:
{
"game_id": 10,
...,
"link": {
rel: resource/site
href: /api/sites/14
}
}
Without more design work, this would mean you'll make a second call to get the site's information. Every design has its compromises :)

Finding out if an Open Graph Object has been liked before

Is there anyway to determine if an object in Open Graph has been liked?
The documentation seem to imply that I have to post a like action on my object and expect an Error 3501 when it has been liked before.
From an UI pov this doesn't make sense, I want to change my like button ui to an "unlike" state without having to like my object and see if it fails or not.
Thanks!
If you're looking specifically for likes on an Open Graph Object (as in the target of an Open Graph Action), and you're talking about built-in (og.likes) likes, Shawn's answer is mostly right, but you need to look in a different FQL table.
An Open Graph Object is just a URL that resolves to a page that has og:type meta in its header. Facebook treats these as link objects (you can check this with SELECT type FROM object_url where url='http://url.to/your/object')
You can find interesting information in the link and link_stat FQL tables, but what you're looking for is the join table where Facebook relates user likes to links: the url_likes table.
So, to tell if the current user has liked a given Open Graph Object, you'd use:
SELECT user_id FROM url_like WHERE user_id=me() AND url='http://url.to/your/object'
If you get a value back, the current user has already liked it. If you get an empty array, the current user has not liked it.
To my knowledge, there's no way to do this with the Graph API, only FQL. I'd love to be proven wrong, though.
Depending on the object, if the object has a like connection you can user the graph api to determain if current user has liked the object.
i use fql in a similar fasion to check if a user likes a post.
/fql?q=SELECT+user_id+FROM+like+WHERE+post_id=\''.$postid.'\'+AND+user_id=me()
refer to post / like https://developers.facebook.com/docs/reference/api/page/

If my app deletes a post it made to a user's wall, will all likes and shares made by other people also be deleted?

Lets say I have a FB app I've created, and for whatever reason the server code for the app is responsible for posting stories to the app user's wall (using a token).
Now let's say we want to take down that post at a later date - easy, right? Because the app created the post, it owns it, and using the ID it received originally it can take that post down. (I presume the ID I get back is actually an "object id" referring to my content, rather than specifically to the post on the user's wall - correct?)
Here's the thing though. What if one or more friends of the user shared that story to their own wall - what if this happened a number of times, spreading through the friend relationship tree further and further. Does my app still have the power to remove all of these posts, because it created the original post?
Additionally, what if the original user deleted the post themselves from their wall, but not until it had been shared by his/her friends? Would this have the same effect (delete everywhere), or would it only be that one specific post being removed? Would my app get an error when it tried to delete the post itself if the post had already been deleted by the user?
The reason I ask is because, if my app deleted the original post that it made to the user's wall, I would want all of the shared posts or likes to also be deleted, no matter where they were down the friend chain. I don't want to delete my original post and assume all is well, only to discover that because it was shared several times down the chain that it is still visible somewhere.
In case it's relevant, the "post" my app will make would require a custom image and a specific return URL - I tried the /user_id/links graph API and it didnt work (there's a bug with it). So I'd be most likely using /user_id/feed to make the post.
if my app deleted the original post that it made to the user's wall, would all of the shared posts also be deleted from everywhere?
Yes
What if the original user deleted the post themselves from their wall, but not until it had been shared by his/her friends? Would this have the same effect?
Yes
How did I know this? I tested it.
I posted a status update to a test user Betty
Then had three other test users share it one after the other
So Tom shared it > Joe shared what Tom shared > Patricia shared what Joe shared
Then for completeness I had Betty share it again
On delete, all posts are gone from all test users, including the re-share Betty made.
As long as the user shares via the action link all subsequent shares will be deleted if the original is deleted.
But if the user manually copies it or saves a photo then re-uploads then no.
In terms of documentation, you have to bite bullet and realize there is no comprehensive documentation for Facebook and not all Facebook engineers know all features about Facebook. There are many items that haven't been able to get a word from Facebook about, and that's when I test things. That's what developers do. Create new test paths, do coverages, make branches and arrive at a conclusion
If you post a link on your user's wall, the shared content cannot be deleted
where as if you post a photo, it will be deleted
If you delete a post (whether it was a link, status update, photo etc), deleting will delete all Likes and Comments from the Object, as well as the related newsfeeds from anyone connected to the object (e.g. it will remove things like Friend has commented on Someone's post etc).
It won't, however, delete any re-shares of that post from users' timeline.