Our app has so many calls to the facebook api, how can I output the error stack trace so we can see WHICH call to the API is causing the access token error?
OAuthException: An active access token must be used to query information about the current user.
I need to be able to pinpoint the LINE NUMBER that THREW the error above
That error is returned by facebook graph api, so you could try to output your request your before you send it, and then output your response that way you will know. This error means that you didn't provided access token, witch must be present with every request to facebook if your using facebook graph api.
Related
i decided to publish posts via api in Instagram so i got access token for it and it worked fine for couple hours but then when i try to publish a countiner i get this
<Response [500]>
{"error":{"message":"An unexpected error has occurred. Please retry your request later.","type":"OAuthException","is_transient":true,"code":2}}
my access token is valid because its work when i make container and i published two posts with this token in the past so its work but i don't know why i get this error on publishing posts
I want to collect all the Facebook link from Facebook search function. What I'm using here is the Facebook graph API tool.
If I want to query the data for a keyword, for example: "limited";
I will use the URL:
https://graph.facebook.com/v11.0/search?q=limited&access_token={my_access_token}
My image
However, I got the result as in the image. When I tried to create a workplace app and tried to get the access token of that app, I got the message as in the second image.
Error message when getting the access token of a workplace app
What I need now is an access token that has the permission to retrieve the data from the Facebook search. After that, I can use python to handle the rest.
Please help me out, thank you very much!
I have to develop an automated process for fetching my Facebook page insights. Since, Access token used for authentication purpose is temporary in nature. Therefore, I created a Facebook App and by providing all required permissions I generated a Page Access Token so that I could extend it's life-span.
Reference Link : Java + RestFB API: Getting fresh Page Access Token without messing with AppID, appSecret
The following is my piece of code :
FacebookClient fb=new DefaultFacebookClient(accesstoken,Version.VERSION_2_7);
Connection<Insight> insights =fb.fetchConnection("119456244790112/insights", Insight.class,Parameter.with("since", "2016-08-01"),Parameter.with("until", "2016-08-27"));
for (Insight insight : insights.getData())
if(insight.getName().equals("page_impressions") && (insight.getPeriod().equals("day")) )
System.out.println(insight.getName()+"\t"+insight.getPeriod()+"\t"+insight.getValues());
'accesstoken' is the short-life Page access-token obtained by following the mentioned link.
The following is the Exception Stack I'm getting :
Exception in thread "main"
com.restfb.exception.FacebookOAuthException: Received Facebook error
response of type OAuthException: Invalid query (code 3001, subcode
1504028) at
com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1191)
at
com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1117)
at
com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1058)
at
com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:969)
at
com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:931)
at
com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:356)
at Main.main(Main.java:31)
Please help me finding the Page Insights using Page Access Token and hence extending it's life-span so that I could produce an automated process out of this. Thanks !
You asked two questions in one.
Extending an access token:
First, you need the user access token. Than extend it (Check the RestFB manual: http://restfb.com/documentation/#access-token-extend) and take the page access token for the page from /me/accounts. The page access token has an unlimited lifetime.
The OAuthException:
If you look at the error message of the exception you should see that the metric is missing. You nee to tell Facebook what metric you like to get. Check the Graph API Reference for valid metrics: https://developers.facebook.com/docs/graph-api/reference/v2.7/insights
Finally I got the success in pulling the Page Insights data using the 'Page Access Token' with extended life-span.
The following is the snippet for making the appropriate requests to Facebook :
Connection<Insight> insights =fbclient.fetchConnection("1388062484542431/insights/page_views/day", Insight.class,Parameter.with("since", "2016-08-01"),Parameter.with("until", "2016-08-30"));
If multiple Metrics need to be passed then we can do so by passing comma-separated names of the required Metrics.
Thanks.
I'm trying to read likes on my friend's status. It is working fine if i copy the access token from the graph api explorer.
If i use the getAccessToken method. It just returns an array with the id of the status, which was passed by me.
Can anybody help me on how to pass the access tokens to the app.
You may say that why don't you continue with the token copied from graph explorer?
But due to the recent changes offline_access token has been removed, so that the token is expiring for every hour. By the way i'm using graph api with php.
The app needs a user access token if the status is not public – otherwise the API can not detect whether the current user is allowed to see it or not.
Get a long-lived access token: https://developers.facebook.com/roadmap/offline-access-removal/
My offline Facebook application is trying to retrieve the accounts associated with a specific user id who has previously authorized the application:
https://graph.facebook.com/(userid)/accounts?access_token=(token)
Even though I am passing a valid access token, Facebook returns:
OAuthException: An access token is required to request this resource.
I verified that my access token is correct by querying the likes connection with the same userid and access token:
https://graph.facebook.com/(userid)/likes?access_token=(token)
For this second statement, Facebook returns the expected result.
My application has manage_pages and offline_access permissions. The access token I am using is the access token Facebook returned when the user authorized the application. I don't understand why it works for the likes connection but not for the accounts connection.
Facebook provides different access tokens, some are shorter and some are longer. Without realizing the difference, I had used the shorter ones, created as type='client_cred'. These work fine for retrieving friends lists, lists of fan pages, publishing to stream etc. but apparently they do not work for getting accounts information.
Here is an example of both types of access tokens. Apparently the first one lacks session information (which is the middle part of the second access token).
116122545078207|EyWJJYqrdgQgV1bfueck320z7MM.
116122545078207|2.1vGZASUSFMHeMVgQ_9P60Q__.3600.1272535200-500880518|EyWJJYqrdgQgV1bfueck320z7MM.
If your access token is wrong facebook returns this:
{
"error": {
"type": "OAuthException",
"message": "Error validating access token."
}
}
It seems that the token is not passed to the graph api. Depending on which SDK you use to pass the token, there are different errors that can occur. The PHP SDK for example ignores the token you pass and tries to get the token from the session cookie, which causes errors. Could you clarify how are you making the graph api calls?
I have verified that with a valid token you can get the accounts data. Have you tried pasting this into your browser https://graph.facebook.com/(userid)/accounts?access_token=(token)?