Facebook Graph API...how to get started? - facebook

Hi I'm trying to get a JSON file about the list of the friends of Bret Taylor ("btaylor" is a profile of Facebook used for practice). I am reading the Graph API official guide (on FB website) and I am undesrtanding that for this request I need an authorization token code.
I've found an access token code from the link
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
grant_type=client_credentials
where I've wrote my aps id and secret code but if I try to open the following URL using the access token code
https://graph.facebook.com/btaylor/friends?access_token=MY_TOKE_AUTH_CODE
I get the following error message:
{
"error": {
"message": "(#604) Can't lookup all friends of 220439. Can only lookup for the logged in user (0), or friends of the logged in user with the appropriate permission",
"type": "OAuthException"
}
}
the token code is something like access_token=112701417077438|GnwE4LeR_f_3r-mmxoi79ukgEFd
Where is the problem? With Google I've found some tutorial with long php pages but following the official guide I can't understand how to use all of this code...on the official guide everything appear extrimely short and easy...

First things first, you need to set up your Facebook application. Go to the Developer App:
https://developers.facebook.com/apps
During the process, you will get an App ID and an App Secret. Take note of them.
What to need to do next depends on the type of app you want to create, either a web app or a app on Facebook. You speak about Access Tokens, so I guess you want to create a web app.
Steps are here, it's pretty easy:
http://developers.facebook.com/docs/guides/web/#login
You will need the infos gathered on the first step.

Related

Facebook API returns "Invalid OAuth access token signature."

For my website I use the Facebook API to get the events from a few Facebook pages. For this purpose I have created a Facebook app.
However, even though this used to work before, the API now returns an error:
"message": "Invalid OAuth access token signature.",
"type":"OAuthException",
"code": 190,
Here are the steps to reproduce the error:
Go to app's dashboard on https://developers.facebook.com/apps
Get the app id (APP_ID) and the app secret (APP_SECRET)
Use the app id and the app secret to get an access token by using this url:
https://graph.facebook.com/oauth/access_token?client_id=APP_ID
&client_secret=APP_SECRET&grant_type=client_credentials
This returns something like
{"access_token":"123412342134|f34f34f32fc3rc4rc324r-X","token_type":"bearer"}
I then use this access token to access the events
https://graph.facebook.com/v2.12/{11239244970}/events/?fields={id,name}&access_token={123412342134|f34f34f32fc3rc4rc324r-X}
However, this returns the error mentioned above, "Invalid OAuth access token signature.".
I'm stuck here. None of the posts on here seem to solve my problem.
I've already tried resetting the app secret, but that didn't help. Any hints are greatly appreciated!
It would appear that the reason for this error is that Facebook currently only returns events for pages using the Pages API if you use a user access token and that user is attending, is interested in or has been invited to the events of the page (as answered by #unknown_b to a related question over here).
To get the Client Access Token for an app, do the following:
Sign into your developer account.
On the Apps page, select an app to open the dashboard for that app.
On the Dashboard, navigate to Settings > Advanced > Security > Client token.
https://developers.facebook.com/docs/facebook-login/guides/access-tokens#errors

Facebook graph API: simple search for users by name

I would like to do a simple search for users by their name from a desktop application using Facebook's graph API. The result I want to have is a list of user names and the link to their profile. I spent several hours reading the documentation but it is still not very clear to me, which access tokens I would need. I have created a developer account on Facebook and added a new app. I've got an app access token and I've tried to do a search using the following URL:
https://graph.facebook.com/search?q=john&access_token={my_app_access_token}
I got the following response:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1
}
}
My question now is, if it is possible to do such a simple search without user access token. So the user sitting in front of my desktop application should NOT have to enter his facebook credentials somewhere - never. Can this be done somehow?
When searching, you should provide the search type (in your case user) and to answer your question, no, a user access token is required to search, app tokens won't work for user searches (documented here)

Can a page on a website get a facebook access token?

I'm fairly new to facebook development and I still get confused about the oAuth thing.
A client of mine asked me to show the latest posts, links and statuses of his facebook page to his website.
On the a php page on his website I'm creating a url
"https://graph.facebook.com/".$clientFacebookPage."/posts?limit=1&access_token= xxx
In order to json decode it and display the info I want, but I don't know how to get an access token. I generated an access token with the graph explorer that is tied to my name as a facebook developer but that expires in 2 hours.
There are many thing that confuse me already and I hope you can point me towards a solution
I've read the documentation but everything revolves around users getting logged on your app and you app posting. So my questions are:
Do I need to create an app to do a curl (requiring special permissions) using the http://graph.facebook/xxxx url?
If so, does the adming of the facebook page need to authorize with the app?
What do I need to do next? I can create a web page using the app id and secret. Does that mean that I can retrieve the info of the facebook page? How?
I know that the page needs an auth token to curl the http://graph.facebook/xxxx page and retrieve the data needed. Where can I generate it? Does the webpage need to generate it, or do I have (as the app developer) acquire the token and write it to my php code?
If I log out of the facebook, will the program/webpage stop functioning?
I hope I didn't confuse you.
Thank you.
The basic process for obtaining an access token for a Page is as follows:
1. Get a user access token for a User who is an admin of the Page
2. Using this User token, request graph.facebook.com/me/accounts and look for the correct Page ID in the list returned.
3. Grab the associated Page token from that ID
4. Use it to do Page stuff.
There is a newly launched Facebook docs guide which shows you how to obtain one of these access tokens in a step-by-step fashion:
https://developers.facebook.com/docs/howtos/login/login-as-page/
Hopefully that guide should help you.
I will also answer your questions in order:
Yes, you will need an app in order to generate access tokens to make API queries
Yes
This is in the guide linked above (start at the Getting Started if you need to create a way to get a User Access Token also)
Again, see the guide above
Yes, but you should follow the steps in this guide to generate a long-lived access token. Once you do that, any Page token you retrieve will last forever.

Get post from a Facebook Page without login

I am trying to get the post of a Facebook Page throw iOS API and I can't do it without login before (without access token). Is there any kind of solution to make this? Does anyone know it?
The App report me the follow error:
An access token is required to request this resource.
UPDATE
I generate one access token with this structure: APPID|APPSECRET and give it an expiration date. With this, I can access to the public data of my Page :)
Thanks,
David
Graph API Documentation seys:
posts [..] any valid access_token or user access_token
More informations you can find there http://developers.facebook.com/docs/reference/api/page/
Here is live example http://developers.facebook.com/tools/explorer/?method=GET&path=19292868552%2Fposts
+1 well... facebook data is all about "user", therefore you always need valid access_token
there are few exceptions though,
for example, you can display user profile picture without token,
see example;
https://graph.facebook.com/100001789213579/picture?type=large

Creating A Test User on Facebook

I am new to Facebook application development. I want to create a test user for my application but when I try it using the API
https://graph.facebook.com/APP_ID/accounts/test-users?installed=true&
name=FULL_NAME&permissions=read_stream&method=post&access_token=APP_ACCESS_TOKEN
It displays the following error:
{
"error": {
"type": "OAuthException",
"message": "(#15) The method you are calling must be called
with an app secret signed session"
}
}
I have read & followed the steps mentioned on
https://developers.facebook.com/docs/authentication/
Still the problem persists. Please guide me, what should I do?
Thank You.
You need to get a valid access token - the application access token will do. To get this use:
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials
substituting YOUR_APP_ID & YOUR_APP_SECRET with your respective values.
This will return a valid access token that you can substitute for APP_ACCESS_TOKEN in:
https://graph.facebook.com/APP_ID/accounts/test-users?installed=true&name=FULL_NAME&permissions=read_stream&method=post&access_token=APP_ACCESS_TOKEN
You need an 'appId' => 'XXXXXXXXXXXXXX' and a 'secret' => 'XXXXXXXXXXXXXX' one.
From the facebook documentation :
In order to authenticate your app, you must pass the authorization code and your app secret to the Graph API token endpoint at https://graph.facebook.com/oauth/access_token. The app secret is available from the Developer App and should not be shared with anyone or embedded in any code that you will distribute
The link seems to be down at the moment though.
You may use the Facebook Test Java API framework, which wraps the process of creating test users in a Java API. The test user also have access to the user details, the wall, and so on so you may create automatic tests to verify your application behavior.