Posting on facebook wall with sdk 3.0 - android

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/

Related

Graph Request Error 500

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

How to get invitable_friends list from facebook using graph API

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

Android: Why it is not possible to upload to facebook album "Profile Pictures"

GraphRequest imagesAlbumPost = new GraphRequest(token, "/1325165102/photos",
bundle, HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
uploadedPhotoId = "";
Log.d("Image Post", "Res =" + response.toString());
}
});
1325165102 is the id of album Profile Pictures (dummy id)
It gives the following exception:
{Response: responseCode: 200, graphObject: null, error: {HttpStatus: 403, errorCode: 220, errorType: OAuthException, errorMessage: (#220) Album or albums not visible}}
Is it normal? Is there any way to upload picture to Profile Pictures?
You can not upload to the user’s profile pictures album any more.
You can only upload to an album created for your app (Facebook will do that automatically, if you post to /me/photos) or you can upload to specific album other than "Profile Pictures" album, and then the user can select to use that image as their new profile image themselves via the Facebook UI.
Hope this helps!
No, it is possible to upload to facebook album “Profile Pictures” but for that u have to create the test users and only to those test users, you can upload pictures

Android: Facebook social context API - getting mutual friends

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();

How can solve OAuthException while i am post a message on facebook

i am doing a sample Facebook application in that i am POST a file to a particular person only, while i am doing this i got an error message like..
05-27 14:33:51.806: DEBUG/Response(2211): {"error":{"type":"OAuthException","message":"(#803) Some of the aliases you requested do not exist: friends"}}
Code:
Bundle b = new Bundle();
accesstoken = facebook.getAccessToken();
b.putString("method", "read_stream");
b.putString("attachment","{\"name\":\"" + "\",\"href\":\"google.co.in"; + "\",\"description\":\"" + "\",\"media\":[{\"type\":\"image\",\"src\":\"" + "" + "\",\"href\":\"" + "\"}]}");
String response = facebook.request("friend_id", b, "POST");
Have you tried to check documentation for facebook and obtain knowledge, that "friends" is wrong, you should use "friend" or "friendlist" instead.

Categories

Resources