facebook app access token mismatch error - facebook

I am trying to send notifications to users via facebook canvas app(SDK 5). My notification code
$response = $fb->post('/userID/notifications?access_token='."$appAccessToken".'&template="test template"&href="test htrf"');
But I am getting an error "Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Access token mismatch. The access token provided in the FacebookRequest and the one provided in the URL or POST params do not match"
I have checked the app access token in graph api explorer and its working fine! I tried to reset the app secret but same error
graph api explorer have no problem with the app access token but when i try to paste the app access token it in my code it shows the error.
I have tried to make app access token by combining app_id|app_secret but no luck.
am i doing it wrong?
Thanks

Related

Manual Facebook login for website - Inspecting Access Tokens

I referred this Facebook page Manually Build a Login Flow to build a login script for my website.
Here is the summary of steps from the page above:
Get authorization code
Exchanging Code for an Access Token
Inspecting Access Tokens
Query Graph Api
On the third step Facebook requires the below parameters
(I used the access token from step 2 here)
input_token {token-to-inspect}
// An app access token or an access token for a developer of the app.
(Should i use my FB app id ?)
access_token {app-token-or-admin-token}
What should the access_token contain? I inserted my FB app id but got the below response
HTTP/1.1 400 Bad Request
WWW-Authenticate: OAuth "Facebook Platform" "invalid_token" "Invalid OAuth access token."
Not sure if the error is due to expired user access token or because of wrong input parameter.
I read further and found this page about app access token
You can either generate an app access token
curl -X GET "https://graph.facebook.com/oauth/access_token
?client_id=your-app-id
&client_secret=your-app-secret
&redirect_uri=your-redirect-url
&grant_type=client_credentials"
or set access_token parameter as below
access_token=your-app_id|your-app_secret
I tried the latter your-app_id|your-app_secret and it worked.

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 "/{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/

Unsupported get request only when using app token

When requesting /703889222997557 via the Facebook Graph API, I am receiving the error "Unsupported get request." But this only occurs when using an app token. When I use the "standard token" you get when opening the Graph API Explorer, the request is successful. As soon as select an App in the Explorer and use the App Token, the request fails again.
Any ideas what the problem might be here?

Facebook Graph API: getting an access token with an app ID and secret

https://developers.facebook.com/docs/facebook-login/access-tokens/:
Here is what I put in my browser:
https://graph.facebook.com/?endpoint&key=value&access_token=[THE APP ID]|[THE APP SECRET]
Here is the result.. an error message:
(#803) Some of the aliases you requested do not exist: endpoint
Help!
Goes to "https://developers.facebook.com/tools/explorer"
Copy the code of "Access Token"
I use "Access Token" as Token for Rfacebook Packages. and it works.
Hope it can work on your side.
The error told everything : endpoint alias does not exist.
If you want to generate the Facebook access token to test, just use the Graph API Explorer:
https://developers.facebook.com/tools/explorer
Or, you should use Oauth process to grant the Facebook app to get access_token.