I am trying to obtain the mutual friends count and data (user id and name) by using the Facebook Social Context API from this documentation: https://developers.facebook.com/docs/facebook-login/social-context/v2.0
The example code from the documentation is shown below, where I have adapted it using the Facebook id that i need.
/* make the API call */
new Request(
session,
"/3003345?fields=context",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
However, my Log shows this error:
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: Syntax error "Expected end of string instead of "?"." at character 7: context?access_token="accesstoken"}, isFromCache:false}
(I replaced the access token with "accesstoken")
Anyone knows the solution to this? I have been stuck for days. Thanks.
I had the same problem but with GraphRequest class, so I'll write for it.
GraphRequest will make URL like this
...facebook.com/3003345?fields=context?access_token=...
instead of
...facebook.com/3003345?fields=context&access_token=...
as it should be.
Solution:
GraphRequest request = GraphRequest.newGraphPathRequest(session, 3003345,...);
Bundle parameters = new Bundle();
parameters.putString("fields", "context");
request.setParameters(parameters);
request.executeAsync();
Related
My app uses Facebook Login Button of facebook-android-sdk.
It was working until last days, now on a graph request on a page's feed
Bundle parameters = new Bundle();
parameters.putString("fields", "id,icon,created_time,name,caption,description,message,link,full_picture,shares");
parameters.putString("limit", "50");
parameters.putString("locale", mLocale);
String pathPosts = path + "/posts";
GraphRequest request = new GraphRequest(
AccessToken.getCurrentAccessToken(), pathPosts, parameters, HttpMethod.GET,
new GraphRequest.Callback() {
#Override
public void onCompleted(
GraphResponse response) {
mResponse = response;
}
});
request.executeAndWait();
I get the OAuthException error
{Response: responseCode: 500, graphObject: null, error: {HttpStatus: 500, errorCode: 1, errorType: OAuthException, errorMessage: An unknown error has occurred.}}
UPDATE
Found that with limit lower-equal than 33 it works without errors
parameters.putString("limit", "33");
For another page's feed the limit must be lower-equal than 7 to work without errors
parameters.putString("limit", "7");
Question:
what is now the rule for the limit in a graph api request for page's feed?
Facebook Graph API has also got a Debug Mode. You need to pass an extra parameter debug=all in the REST API. It will give you the reason for the issue too in the response JSON if there is any issue.
Quoting Facebook documentation -
When Debug Mode is enabled, Graph API response may contain additional
fields that explain potential issues with the request. To enable debug
mode, use the debug query string parameter. For example:
GET graph.facebook.com /v2.3/me/friends
access_token=...&
debug=all
In your code, try changing this
String pathPosts = path + "/posts";
to this
String pathPosts = path + "/posts&debug=all";
Or
Add and an extra parameter "debug" "all" in your Bundle
and check what debug message you got
For more info on handling errors and debugging Graph API, see here - https://developers.facebook.com/docs/graph-api/using-graph-api/#errors
I want to get invitable_friends from facebook.While using the this code:-
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/invitable_friends",null,
HttpMethod.GET,
new GraphRequest.Callback()
{
#Override
public void onCompleted(GraphResponse response)
{
/* Handle the result */
System.out.println("=========================");
System.out.println("==>> :" + response);
System.out.println("=========================");
}
}).executeAsync();
I am getting this error
Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 100, errorType: OAuthException, errorMessage: (#100) No permission to access invitable_friends
Can any one please tell me how to set invitable_friends permission and how can I get invitable_friends list.
Thanks in Advance..!!
This feature is only available to games with a presence on Facebook Desktop
Source: https://developers.facebook.com/docs/games/services/gamerequests#invitablefriends
You can only use this for games with a Canvas implemenation.
How to invite friends to a non-game App is explained in the FAQ: https://developers.facebook.com/docs/apps/faq
I am able to see facebook groups when I run app for the first time.
But when I close the emulator and run my application again, I am getting the following response.
{Response: responseCode: unknown, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: java.net.UnknownHostException: Unable to resolve host "graph.facebook.com": No address associated with hostname}, isFromCache:false}
I used the following code for fetching Facebook groups:
Request request = new Request(session, "/me/groups", null, HttpMethod.GET,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
//code for displaying groups in list view as response contains groups information
});
request.executeAsync();
Am I missing any session handling use cases?
I am trying to update an old code using Facebook 2.0 SDK.
As stated in the upgrade guide https://developers.facebook.com/docs/android/upgrading
I am creating a new session from a valid saved access token using:
AccessToken accessToken = AccessToken.createFromExistingAccessToken(
access_token,
new Date(getExpiration), null, null, Arrays.asList(getResources().getStringArray(R.array.facebook_permissions)));
session.open(accessToken, new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
Session.setActiveSession(session);
}
});
The session then is then opened with state:
{Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[email, user_birthday, user_checkins, user_hometown, user_location, publish_stream, publish_checkins, friends_location, friends_hometown, friends_work_history, friends_education_history]}, appId:####}
But now every time I do any request (Graph, HTTP) using this session, It will CLOSE and I will receive a 400 error:
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 190, errorType: OAuthException, errorMessage: Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session was created or Facebook has changed the session for security reasons.}, isFromCache:false}
Again the token is valid and tested on the web's debug page.
I'm trying to post a message on user's wall defined by it's ID, but in response I'm getting an error "Unknown method".
My code is:
final Bundle params = new Bundle();
params.putByteArray("message", "Test".getBytes());
params.putByteArray("name", "American Virgin".getBytes());
params.putByteArray("link", "http://bit.ly/12345".getBytes());
params.putByteArray("description", "A Freshman College Girl on a scholarship from an ...".getBytes());
params.putByteArray("picture", "http://xxx/MOV1026.jpg".getBytes());
final Request postToWall = Request.newRestRequest(Session.getActiveSession(),
"/" + pickedUsersId.get(0) + "/feed", params, HttpMethod.POST);
postToWall.setCallback( new Request.Callback()
{
#Override
public void onCompleted(Response response)
{
Log.i(Utils.LOG, response.toString());
}
});
Request.executeBatchAsync(postToWall);
In LogCat i have:
11-08 17:34:29.136: I/LOG(21699): {Response: responseCode: 200, graphObject: null, error: {FacebookServiceErrorException: httpResponseCode: 200, facebookErrorCode: 3, facebookErrorType: null, message: Unknown method}, isFromCache:false}
Everything looks right except the graphPath parameter in your Request method. Instead of:
"/" + pickedUsersId.get(0) + "/feed"
do:
pickedUsersId.get(0) + "/feed"
There should not be a leading slash "/" in front of your graph path. You can always refer to our documentation to see how exactly to publish to feed. https://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/