Facebook access token with "never-expire" - facebook

I'm trying to get a Facebook access token that never expires but I cannot manage to do it. Here is my steps:
1) Use Facebook graph explorer to generate a short live access token with the desired permissions (this token is valid for 1h or so)
2) Get a long live token (2 months expiry time) by manual GET request to
https://graph.facebook.com/oauth/access_token?
grant_type=fb_exchange_token&
client_id=[app-client-id]&client_secret=[app-secret-id]& fb_exchange_token=[short-live-access-token]
3) An this tohttps://graph.facebook.com/[user-id]?fields=access_token&access_token=[long-live-access-token]
but that last steps show an error:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (access_token) on node type (User)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "DpmM6CyzoAt"
}
}
I have found that last step somewhere on the net so I presume FB must have change something, I have read their api doc but I cannot figure out by what resource they chance the step 3.
Could someone explain me how to get a user access token that never expires ?
thank you

User Tokens are never valid forever, an extended one is only valid for 60 days as you have found out already. I assume you want to get an Extended Page Token, that´s how you can get one:
https://graph.facebook.com/[page-id]?fields=access_token&access_token=[long-live-user-token]
Basically, you just need to use a Page ID, it does not work with a User ID.

Related

Sudden Instagram API "SCOPE" issue when trying to authorize user and get token - OAuth

I seem to be getting an error around scope when trying to create a token via the Instagram API. This was working perfect until about a week ago. If I remove scope then it works, but if I do that I can't access Hashtag searches, so I need that scope.
I keep getting the following error:
{"error_type": "OAuthException", "code": 400, "error_message": "Invalid scope field(s): public_content"}
This is the request URL:
https://api.instagram.com/oauth/authorize/?client_id=***CLIENTID***&approval_prompt=force&scope=public_content&response_type=code&redirect_uri=***REDIRECT URL***
My app has permissions for public_content as seen here:
Any ideas?
Remove "public_content". Only use "basic".

Facebook Open Graph API Examples - How to get the access token?

Facebook has some great-looking examples of Open Graph requests here:
https://developers.facebook.com/docs/reference/api/examples/
The problem is that since I don't have an access token, most of the examples just return
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
I understand access tokens, but how do I get the token so that I can experiment with these example requests?
As long as you only want to test...
Use the Graph API Explorer to generate a token with the permissions you want.
Don't hesitate to select all of them.
Then, just copy/paste the token at the end of each graph.facebook.com URL. For instance:
https://graph.facebook.com/v1.0/me/friends?access_token=<ACCESS_TOKEN>
The day you want to get the access taken for an app...
Start by reading this doc.

Facebook access token extending - "The access token does not belong to application xxx"

I went to https://developers.facebook.com/tools/explorer?method=GET, set up there ID of my Facebook page, set up there the correct permission for posting statuses on my FB timeline and generated access token.
Then I wanted to extend this short-live token on the long-term (60 days long valid token). So I did following - I put this URL to the browser:
https://graph.facebook.com/oauth/access_token?client_id=APP_ID_OF_MY_FB_APP&client_secret=SECRET_ID_OF_MY_APP&grant_type=fb_exchange_token&fb_exchange_token=GENERATED_ACCESS_TOKEN_FROM_THE_FIRST_STEP
and in the browser I saw this error message:
{
"error": {
"message": "The access token does not belong to application APP_ID_OF_MY_FB_APP",
"type": "OAuthException",
"code": 1
}
}
Which is weird, because the APP_ID of my Facebook app is correct, I've tried to post on the wall of the Facebook page and it was working.
But when I try to get extended access token, I am getting the error above.
What's wrong with the access?
Thank you
This almost certainly means what the error says, which is that GENERATED_ACCESS_TOKEN_FROM_THE_FIRST_STEP is not actually from the app ID that you're using in the APP_ID_OF_MY_FB_APP parameter
Check the access token you're trying to extend in Facebook's Debug Tooland ensure it was actually generated for your app
Your AppID param is not the same to the AppID in developers.facebook.com

Facebook non-expiring access token

I want to show the last facebook post on my website. I have a script for it but it needs access token to work.
I followed the steps mentioned in this post:
https://neosmart-stream.de/de/facebook/how-to-create-a-facebook-access-token/comment-page-1/#comment-617
Now I've got an access token with an expiry period of 60 days but
when I open https://graph.facebook.com/me/accounts, I get this error:
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
as my access token validity is 2 months, It is supposed to work.
1: Create an application in facebook with your website url
2: Run this link in your browser
3: Visit the following to generate a new SHORT-LIVED (1 hour) access token:
https://www.facebook.com?client_id=[APPID]&client_secret=[APPSECRET]&redirect_uri[http://APPURL]&scope=manage_pages,read_stream&response_type=token
4: Take that short-lived access token and send it here:
https://graph.facebook.com/oauth/access_token?client_id=[APP_ID]&client_secret=[APP_SECRET]&grant_type=fb_exchange_token&fb_exchange_token=[EXISTING_ACCESS_TOKEN]
5: Then, either in FB’s Graph API Explorer or on your own, visit here:
https://graph.facebook.com/me/accounts?access_token=[TOKEN]
Then paste the token and id in the code, then you will get the result.
You can debug and verify the expiration date of your token using the FaceBook Access Token Debugger:
when i'll open https://graph.facebook.com/me/accounts...
You need to open it in the Graph API Explorer and add the access token retrieved in the earlier step or append it to end of the url
https://graph.facebook.com/me/accounts?access_token=XXXX

Facebook Graph API Error (access token)

I'm getting the following error when I try to access the Graph API with my access token:
{
"error": {
"message": "Expected 1 '.' in the input between the postcard and the payload",
"type": "OAuthException",
"code": 1
}
}
I'm grabbing the access token after successfully authenticating an app I'm working on. I have accepted the permissions and I'm hitting the app's landing page. The access token doesn't look like others I've seen online. It doesn't have the '|' character in it. It does have a period and some underscores along with the typical alphanumeric combination.
I figured out the problem. The other developer I was working with used part of the raw signed_request object (not parsed) to form the access token. After taken a gander at the documentation, I quickly realized that you need to parse the signed_request object first before obtaining the oauth_token value. After that was fixed, I was able to easily make an API call.
Check to ensure you are verifying the "code" parameter returned by Facebook before signing the request, not the "access token". Signing a request with a bad access token produced this error message for me.