I try to create a common object with this code:
Bundle params = new Bundle();
params.putString("type", "fitness.course");
params.putString("url", "http://samples.ogp.me/136756249803614");
param.putString("title", "Sample Course");
params.putString("description", "");
Request request = new Request(
Session.getActiveSession(),
"me/objects/fitness.course",
params,
HttpMethod.POST, new Request.Callback(){
#Override
public void onCompleted(Response response) {
if(response.getError()==null)
System.out.println("Object succesfully created!!");
else
System.out.println("Object NOT Created!!"+response.getError());
}}
);
Response response = request.executeAndWait();
but I read this in my Logcat:
10-07 15:33:04.009: I/System.out(23284): Object NOT created!! {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: Cannot specify type in both the path and query parameter.}
I dont understand the error message... What do I do to create a Course object and update the data (gps status) of my course? I need of a back end server to store the data of my course? The back-end server is only an option?
Your error message says all, you're supplying og:type from both your POST request and your URL.
As of the new FB OpenGraph SDK, you can have ad-hoc URL-less objects. What you're trying to do is use that API while at the same time using the self-hosted version of the API.
I'd suggest either taking the URL parameter out, taking og:type out of the URL you have set up, and definitely giving the documentation a second read. Here is the documentation for self hosted objects and here is the article for app owned objects.
Related
I implemented this code from the Facebook SDK to get mutual friends.
Bundle params = new Bundle();
params.putString("fields", "context.fields(mutual_friends)");
// make the API call
new Request(
session,
"/{user-id}",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
Log.d("results", response.toString());
}
}
).executeAsync();
How do i read the Response object and retrieve the total count and the list of mutual friends? I have successfully gotten the result in the log.
Thanks.
Booth people need autorize your friend_list_permission to you see the users in common. If not you need use all_mutual friends, but you just can run this in server, no working in clients. look documentation in all_mutual_friends.
I explain this post here.
https://stackoverflow.com/a/34663235/3516549
I would like to get realtime_update when user's friendlist changes and am trying to subscribe to friends object .I have the code below where I added params.putString("access_token", "12|wewee"); because I used to get {This method must be called with an app access_token.}, isFromCache:false} .Now I get the response as displayed below.I would like to get realtime subscription .How do I make it work? I really appreciate any help.Thanks in Advance.
code:
Bundle params = new Bundle();
params.putString("object", "user");
params.putString("access_token", "12|wewee");
params.putString("callback_url", "http://example.com/callback/update.php");
params.putString("fields", "friends");
params.putString("verify_token", "1234");
/* make the API call */
new Request(
session,
"/12345/subscriptions",
params,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
Note: session =fb.getsession();
added param to get app_access_tokem:
params.putString("access_token", "12|wewee");
and I get this response :
{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"FACEBOOK_NON_JSON_RESULT":null}}, error: null, isFromCache:false}
It's my fist post here, so please, go easy :)
I'm integrating Facebook SDK in an Android application. After the user logs in, I want to show him the app's last post in facebook, so I'm triYng to get it with(as graph object):
Bundle params = new Bundle();
params.putInt("limit", 1);
Request request = new Request(session, inRequestId + "/posts/?limit=1&access_token=" +
session.getAccessToken().toString(), params, HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) {
if(response != null){
if(response.getError() != null)
Toast.makeText(getActivity(), "Error retrieveng last post", Toast.LENGTH_SHORT).show();
else {
updateFacebookView( response.getGraphObject().getInnerJSONObject() );
}
}
}
});
request.executeAsync();
This works, fine I think, but if I'm triyng to make it without graphPath's limit=1 parameter (inRequestId + "/posts/?access_token=" + session.getAccessToken().toString()), it has no limit, and if I don't put bundle param "limit", (as string or as int tested), it gives me this error:
09-30 17:51:47.094: E/caca(19703): {HttpStatus: 400, errorCode: 190, errorType:
OAuthException, errorMessage: Malformed access token
CAAT76i2gxTgBAKyLzc8SI6y7V1pGJ0fmbLWCtuKdhHIEZAQBA0jYx4YqZB8IgRDJMUlw1XrvZCLJ8kxKdZCRG3LNbrVL8fB34ZBlyvlqadT192MCWMkst1lMSdFwtRVPWiSNfBfi8Gq2RHZCWskrBVTjAwPDKyDMGLSU8sPnXfe0r2tsZBdZCXLCOJGQtE76sJkr7n8SdOU4j1KopkvT0Mux7QBGf7ZBXtCRqDnsZAZCxSNHAZDZD?access_token=CAAT76i2gxTgBAKyLzc8SI6y7V1pGJ0fmbLWCtuKdhHIEZAQBA0jYx4YqZB8IgRDJMUlw1XrvZCLJ8kxKdZCRG3LNbrVL8fB34ZBlyvlqadT192MCWMkst1lMSdFwtRVPWiSNfBfi8Gq2RHZCWskrBVTjAwPDKyDMGLSU8sPnXfe0r2tsZBdZCXLCOJGQtE76sJkr7n8SdOU4j1KopkvT0Mux7QBGf7ZBXtCRqDnsZAZCxSNHAZDZD}
Am I not using this correctly or it's a bug?
Thanks in advance
The second parameter for the constructor is the "path" of the request, but you're also putting request parameters into the path, which messes with the other parameters the Request class may try to put on your behalf. A couple of things to do:
Don't put request parameters in the path parameter, stick them into the "params" bundle.
Don't put the access token (the Request class automatically gets it from the session object).
Try something like this:
Bundle params = new Bundle();
params.putInt("limit", 1);
Request request = new Request(session, inRequestId + "/posts", params, HttpMethod.GET, new Request.Callback() {
...
});
request.executeAsync();
From within my Android application, i am trying to implement a simple "Like Button" functionality.
We have already executed Facebook log in from the same app.
We have also created an Open Graph Like action & a Link object as well on our App's Dashboard.
This is the code that we are using to publish the like.
public static void likeFacebookPage(Context context,String pageUrl)
{
Bundle params = new Bundle();
params.putString("object",pageUrl);
Request request = new Request(
Session.getActiveSession(),
"me/og.likes",
params,
HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response
}
In the pageUrl parameter, we have:
http://www.facebook.com/<object_id>
"object_id" is the Id of the Link Object that we have created in Open Graph.
After executing the above method, the response object received as follows:
{Response: responseCode: 200, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}
But the Like count is not getting updated, leading us to believe that this process is not working.
We have also included the permissions "publish_actions" & "user_likes" in our code as well as on the App Dashboard.
Kindly help us with configuring this functionality.
Thanks in advance.
As described here https://developers.facebook.com/docs/reference/api/publishing/ you publish a like to an object like so with the publish_actions and publish_stream permissions:
Bundle postParams = new Bundle();
Request request = new Request(Session.getActiveSession(),
FB_OBJECT_ID+"/likes", postParams, HttpMethod.POST, new Callback() {
#Override
public void onCompleted(Response response) {
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
Where your FB_OBJECT_ID is simply the ID of the object. I.e if you want to like a photo, FB_OBJECT_ID would be the pid. For an album, FB_OBJECT_ID would be the aid.
I'm using the following snippet to request the friendslist of the authorized user:
System.out.println("AT: " + facebook.getAccessToken());
String response = facebook.request("me/friends?fields=first_name,last_name,id,gender");
The response I get:
{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
I'm printing the accesstoken, this gives me a valid token. Also, getAccessExpires() returns a time in the future. When I request the url "me/friends" without any params, I get the expected (but with less data) friends list without errors.
How can I solve this?
String response = facebook.request("me/friends?fields=first_name,last_name,id,gender");
That is the incorrect way to use facebook.request. I'm assuming you're not using the beta Android SDK so the correct way to do this is to do the following:
Facebook facebook = new Facebook(YOUR_APP_ID);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
Bundle params = new Bundle();
params.put("fields", "first_name, last_name, id, gender");
mAsyncRunner.request("me/friends", params, new RequestListener() {
// get response here
....
});
Hope this helps.