Getting App Access Token for facebook app? - facebook

I have read this:
trying to get app access token
And it doesn't work...
I'm getting the following error:
"error": {
"message": "An active access token must be used to query
information about the current user.",
"type": "OAuthException",
"code": 2500
}
I need the app access token in order to create open graph objects that are owned by the application.
I know how to create objects owned by the users, but I just cant find the correct way of creating the App access token.
AppId -> doesn't work...
AppId|AppSecret -> doesn't work....
App ClientToken -> doesn't work....
Anyone know this?

You can get it directly from the Access Token Tool.
Please note: For security, app access token should never be hard-coded into client-side code, doing so would give everyone who loaded your webpage or decompiled your app full access to your app secret, and therefore the ability to modify your app. This implies that most of the time, you will be using app access tokens only in server to server calls.

It looks like you have a valid token, you're just trying to query for the current user. If you're using the app token, however, there isn't a current user, so it's failing.

If you are using Java language to fetch app access token, you can try this:
DefaultFacebookClient facebookClient = new DefaultFacebookClient(Version.LATEST);
AccessToken accessToken = facebookClient.obtainAppAccessToken(clientId, clientSecret);
System.out.println(accessToken);
To check whether it is valid, use access token debugger.

Related

Facebook Graph API "/{page-id}/feed" is not working with App Access Token

We are facing issues with Graph API. The Facebook Graph API "/{page-id}/feed" is not working for all pages with a valid App Access Token. Previously it used to work. We noticed it today the API is throwing error
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1
}
}
Not working pages:
https://graph.facebook.com/22934684677/feed?access_token=
https://graph.facebook.com/42798291365/feed?access_token=
Note: And its working if we pass a User Access token instead of App Token.
Facebook developer Docs says "An access token is required to view publicly shared posts." So App Access Token should work!
Does Facebook change something inside the API?. Can any one help to solve the issue
You should use a Page Token for Page data. Pages not working with an App Token are most likely restricted by age or location. Since the App Token does not include any user session, you canĀ“t be sure if the user should have access to it.
If it does not work with an App Token AND the Page is definitely not restricted, file a bug.
This is happening because some of the posts returned might have extra restrictions on them which need a user token to verify this. Use a page token or a user token as a workaround for this. Having said that, the request shouldn't fail with an unknown error and we're working on a fix for the same on the bug report here:
https://developers.facebook.com/bugs/783169051760311/

Facebook token for searching groups

I have created an application on developers.facebook.com from my profile. Get APP ID, APP SECRET and generate TOKEN. Now, when I send the request like
https://graph.facebook.com/search?q=media&type=page&access_token=MY_TOKEN
is ok, but when I try to send the request for GROUP, like
https://graph.facebook.com/search?q=media&type=group&access_token=MY_TOKEN
I get the error
The remote server returned an error: (403) Forbidden.
Seems I have permissions problem. I set the permissions friends_groups, user_friends, user_groups to the account, but.. still the same error...
Can you please tall me what am I doing wrong? Maybe I need a different token?
As I understand you're using an App AccessToken for an endpoint (object type) which needs a user AccessToken. See the docs at https://developers.facebook.com/docs/graph-api/using-graph-api/#search
It's stating
"All Graph API search queries require an access token included in the request. The type of access token you need depends on the type of search you're executing.
Searches across Page and Place objects requires an app access token.
All other endpoints require a user access token."

Facebook open graph says access_token needed

I'm trying to post the following the facebook Graph API explorer.
cody.short.94/notifications? access_token= {User Access Token} &template= this is a test &href= www.test.com
I want to be able to send the user a notification, but all attempts have failed. I'm currently getting this error:
{
"error": {
"message": "(#15) This method must be called with an app access_token.",
"type": "OAuthException",
"code": 15
}
}
I'm not sure what is causing it, and I'm in need of some guidance. Any help would be appreciated. note: my app is currently marked for web so that it not the problem
See, the error is quite self-explanatory :
This method must be called with an app access_token
The Notifications API use the APP Access Token, not the user access token!
The App Access Token is: APP_ID|APP_SECRET or get directly from here for testing. (Make sure of the security of this token, this is very crucial and just like a password to your app)
Now test the query with Graph API Explorer , and remove the user token from the Access token field and replace it with the App Access Token
It will look something like this-
Make sure you paste the app access token APP_ID|APP_SECRET on the top field that says Access Token

Getting access token for CURL/Browser Graph API

I'm trying to obtain messages and attachments from Facebook, I'm using:
https://api.facebook.com/method/message.getThreadsInFolder?access_token=AT&folder_id=0
To get the list of threads and:
https://graph.facebook.com/fql?access_token=AT&q=QUERY
For my queries.
But, every time, I copy the access token generated by the Graph API Explorer as I don't seem to be able to get it programmatically:
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=ID&client_secret=SECRET
Gives me an access token, but it doesn't work. If I try to use it with the URLs above I get:
"error_msg":"A session key is required for calling this method"
And for the second one:
"message": "Invalid OAuth access token.",
"type": "OAuthException",
"code": 190
The Facebook documentation it's really unclear.
I do not want to use a login flow, is there a way to login programmatically with the stored credentials as the mobile application does?
You need a login flow which you are not using (https://developers.facebook.com/docs/facebook-login/). It is not possible to get a user access token programmatically. This defeats the point of manual user interaction. The user must explicitly grant access to your application.

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.