When exploring the Facebook Graph API, at: https://developers.facebook.com/tools/explorer The default example is get my name & id (under the assumption the browsers logged to my Facebook account). All good and I get my correct Id (facebook.com/id redirect to my profile).
So here is the thing: Exploring network traffic via developer console, I noticed some ajax have user id as url param, and the id is totally different from the previous one:
Same length
Much more zeros
So I tried same thing: facebook.com/new_id and same result: Redirect to my correct profile page.
How is that each user have 2 different id's?
It’s called app-scoped user ids, see https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
Related
Goal
My goal is for a user to share something he created on my site to Facebook, and for me to display all comments on my own page using the Facebook comments plugin.
So my ideal flow would be:
User creates content with example id vjrjf834fdkfj, and shares using public URL http://example.com/vjrjf834fdkfj/.
User shares this URL on Facebook via my Facebook app ID. The post ID is 1234567.
I get this post ID. (This is what I need help with)
I store this in my database.
Whenever a visitor visit the page http://example.com/vjrjf834fdkfj/ I look up in the database what the post ID is (1234567 in this example), and call the Facebook comments plugin using this post ID.
What I tried
Attempt #1
First failed attempt: read the post_id field of the FB.ui callback but this response is typically empty because Facebook says that:
Only available if the user is logged into your app using Facebook and
has granted publish_actions. If present, this is the ID of the
published Open Graph story.
My user is not always logged into my app via Facebook, because he can also create a normal account.
Attempt #2
So my next attempt was to get a list of all posts of this app by calling the Graph API. I have a "basic" app with the "Website" platform set to my website URL (www.example.com). Given this list I might filter this on the relevant URL and voila, get the post ID for the right URL.
I can create an access token and call https://graph.facebook.com/v2.8/{app-id}/objects?access_token={token}, but this gives an error The parameter type is required. And when I try to get a list of object types by calling the /object_types endpoint, I get an empty list.
Attempt #3
I also played a bit with creating a Page Tab but the documentation makes no sense to me as to how that would apply to my case. I ended up with two extra pages, all empty, and not what I want. However, I could live with an extra page on my Facebook page showing a list of all posts that have been shared (so these posts would appear here and on my user's timeline).
Questions
So:
Why is this object_types list empty? I expect that something like "post" would show up here, allowing me to get a list of all posts associated with this app ID.
If this is not possible, how can I still achieve my end goal?
Thanks.
I am planning to build a small side project that stores posts from particular public pages. And detect if they delete the post later. Something similar has been done for Twitter. But I couldn't find similar projects for Facebook.
Like this: http://politwoops.sunlightfoundation.com/
But for Twitter. I will do it in Python or C#
How can I go about it?
Any particular code or projects I can learn from?
The only way to check if a post is not there anymore on Facebook is to search for it with a User Access Token of the User who posted it. Every Object on Facebook gets a specific ID, you only have to check if that ID still exists. If not, you get an Error from the API.
For example: https://developers.facebook.com/tools/explorer/?method=GET&path=10203433018378479&version=v2.0
The path parameter is the ID of the Post.
Keep in mind that you need the read_stream permission for that, and you need to let Facebook approve it for other users or it will only work for Admins/Devs of your App. It is not very likely that you will get the permission approved for this though. It usually only gets approved for Apps on "Platforms without a native Facebook experience".
Edit: My bad, i was thinking about User posts, but your question was about Pages. In that case, all you need is an App Access Token (App-ID|App-Secret). The API Call would be the same, you just need to know the Post ID.
About Access Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens/
http://www.devils-heaven.com/facebook-access-tokens/
For getting the feed of a Facebook Page, see the Facebook docs (including code samples): https://developers.facebook.com/docs/graph-api/reference/v2.0/page/feed/
You can use graph api for this. If it's a public page, you can follow these steps:
Create your application in Facebook developers site
Setup the basic graph auth mechanism with your favorite language and get unexpired token.
Use your unexpired access token to do these tasks:
Enter the id of the pages you want to crawl http://graph.facebook.com/[insert page id or url here]/feed
Add post title, postID to your database.
Create a scheduled task on your server to do these tasks:
Select all / page based etc posts on your database and send a request to: http://graph.facebook.com/[insert post ID here]
if it returns it means it's still there. otherwise it will return an error.
I have a simple tab page, php sdk working and I know I can get the "like" for this specific page from the user signed_request.
This page is a colaboration with another company who also has an FB page. What i´d like to know is if I can get the like status of their page for the current user so I can authorize an action on this tab that is dependant of the user liking both my page and my partner´s.
Is this possible without using an actual app, an access_token and the appropriate perms requested?
e.g. my page is fb.com/Coke and my partner is fb.com/Target
On this specific tab page I want to enable a button only if me (Coke) is liked (which I can get already) and if my partner (Target) is also liked.
I tried the graphAPI (me/likes) and FQL (using the connection table) and both compalin of an unauthorized request.
Short Answer:
No, this will not be possible in a production setting.
Further explanation:
Some users have their list of likes as public. In that case, it would work.
But in order to get likes from a user that has that setting as anything but public (such as myself, only friends of friends can see it), then it requires an app and an access_token that has a user_likes permission.
From the documentation:
Permissions Required:
user_likes permissions if querying the current user.
I've had a look through Facebook's online documentation and cannot find a way to manually construct a Facebook user's profile picture Uri using the user's third party ID (third_party_id) field.
For example (doesn't work):
https://graph.facebook.com/<FACEBOOK_THIRD_PARTY_ID>/picture?type=square
http://developers.facebook.com/docs/reference/api/user/
third_party_id: An anonymous, but unique identifier for the user; only returned if specifically requested via the fields URL parameter
Using Facebook ID:
Using the user's Facebook ID to retrieve their profile picture image Uri works:
https://graph.facebook.com/<FACEBOOK_ID>/picture?type=square
For example (works):
<img src="https://graph.facebook.com/568916752/picture?type=square" />
Using Facebook Username:
Using the user's Facebook username to retrieve their profile picture image Uri works:
https://graph.facebook.com/<FACEBOOK_USERNAME>/picture?type=square
For example (works):
<img src="https://graph.facebook.com/brett.scott/picture?type=square" />
Facebook Third Party ID:
Best practices suggests that I store the user's third_party_id instead of the user's Facebook ID (id) in my database. I shouldn't be publicising a user's Facebook ID to other user's of my website. The reason? Because once a user can see another user's profile picture Uri, which contains their Facebook ID, they can find the other person's profile (see example below). I'm sure there's other reasons too.
Load profile picture:
https://graph.facebook.com/brett.scott/picture?type=square - or -
https://graph.facebook.com/568916752/picture?type=square
Then any user can load the above user's profile:
http://www.facebook.com/brett.scott - or -
http://www.facebook.com/568916752
I do not want to make a request using the Facebook Graph to obtain each user's profile picture Uri picture because it's too slow. If there are 20 Facebook pictures on a page, that's 20 HTTP requests back to Facebook's servers. I'm aiming for zero.
Is there another way to obtain a Facebook user's profile picture using their third_party_id or is it a missing feature?
https://graph.facebook.com/<FACEBOOK_THIRD_PARTY_ID>/picture?type=square
For example (third_party_id generated for my application):
https://graph.facebook.com/0u0JrPIriHa3fgEDostj7v8dbdo/picture?type=square
The Third Party ID is a unique, but anonymous identifier. It is meant to allow an advertiser to track unique users. It is specifically designed to NOT be resolvable to a Facebook ID.
For your site, you can store Facebook user ids in your database without violating the TOS, so long as you keep that data private.
When you request a photo from the Graph API, Facebook returns a CDN URL to the photo. You can publish that URL. You aren't supposed to store this data for longer than would be expected in a cache.
To get 20 pictures in one call, you can call the endpoint:
https://graph.facebook.com/picture?type=square&ids=UID_1,USERNAME_2,...UID_n
is that possible we can get the information from facebook API whether graph or REST or FQL regarding user sharing. Such as video or post or anything can share via facebook and it is shared by a list of user, with profile id or user name. I found something like this http://appshack.tv/2011/03/likes/ but it is just the counter, lack of information. Any way can do? Coz I found that facebook not stated everything in the documentation. Some trick is found from third party side.
No you can't get the user ids. Facebook will do their best NOT to share the user id with you "unless" they (the users) authorize your application.
And guess what....you can't even get the list of the users who are using YOUR application! (You can only get the count!)
Check this answer.