I want to test the publish permissions for my facebook app, however when using the graph api(s) to either like or comment, I get an error from the facebook server.
The code being used to post a like is as below:
Bundle params = new Bundle();
params.putString("url", "http://www.imdb.com/title/tt2015381/");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + facebookObjectId + "/likes",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i(TAG, "FACEBOOK GRAPH RESPONSE FOR POSTING LIKE: " + response);
}
}
).executeAsync();
The corresponding error that is being generated is:
FACEBOOK GRAPH RESPONSE FOR POSTING LIKE: {Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) App does not have permission to make this call}}
essentially suggesting that App does not have permission to make this call
To post custom like:
Bundle params = new Bundle();
params.putString("object", linkURL);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + Profile.getCurrentProfile().getId() + "/og.likes",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i(TAG, "FACEBOOK GRAPH RESPONSE FOR POSTING LIKE: " + response);
}
}
).executeAsync();
To delete custom like:
Bundle params = new Bundle();
params.putString("object", linkURL);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + likeActionInstanceId,
params,
HttpMethod.DELETE,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i(TAG, "FACEBOOK GRAPH RESPONSE FOR DELETING LIKE: " + response);
}
}
).executeAsync();
Here the likeActionInstanceId is the id received after submitting the like successfully.
NOTE: Comments can't be added as of now from your own app. Comment Mirroring is in beta phase at Facebook.
Related
I am trying to fetch Cover Photo of an album using Graph API.
Here is my code:
Bundle params = new Bundle();
params.putString("type", "thumbnail");
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + albumID + "/picture",
params,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.v("TAG", "Facebook Photos response: " + response);
}
}
).executeAsync();
Using above code, I am getting below response:
{Response: responseCode: 200, graphObject: {"FACEBOOK_NON_JSON_RESULT":"����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000�Photoshop"}, error: null}
Can anyone help me what is wrong with my request and how I can get a cover photo of an album?
Thanks in advance.
After googling, I found a solution and its working fine for me.
I have changed Bundle parameters as below:
Bundle params = new Bundle();
params.putString("type", "thumbnail");
params.putBoolean("redirect", false);
Rest of code as it.
After changing, I am getting proper response same as I get in Graph API browser:
{Response: responseCode: 200, graphObject: {"data":{"is_silhouette":false,"url":"https:\/\/scontent.xx.fbcdn.net\/v\/t1.0-0\/s180x540\/13782019_1735895746671060_1058868038400371031_n.jpg?_nc_cat=0&oh=506c19df47791a4b7fcfc362eeed0676&oe=5B92AA68"}}, error: null}
We have a sharing facility in our App where we facilitate sharing images/videos to Facebook. We are using Facebook Android SDK 4.27.0 for Facebook login and sharing.
Now, the images/videos are present on our own server(i.e, the media is not present on my device) and we intend to share these directly with Facebook using a Graph call. Here is the working implementation of photo sharing:
Bundle postParams = new Bundle();
postParams.putString("name", itemdesc);
postParams.putString("url", itemurl);
new GraphRequestAsyncTask(new GraphRequest(
AccessToken.getCurrentAccessToken(), "me/photos", postParams, HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
// Do something with the error
}
})).execute();
But, a similar implementation for videos is not working:
Bundle postParams = new Bundle();
postParams.putString("name", itemdesc);
postParams.putString("url", itemurl);
new GraphRequestAsyncTask(new GraphRequest(
AccessToken.getCurrentAccessToken(), "https://graph-video.facebook.com/me/videos", postParams, HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
}
})).execute();
For the endpoint, "https://graph-video.facebook.com/me/videos", I get the following response on sharing with a test user:
{Response: responseCode: 200, graphObject: {"id":"10150481253673034","url":"https:\/\/graph-video.facebook.com\/me\/videos"}, error: null}
But, the video doesn't show on the test user's timeline.
And for the endpoint, "me/videos", I get the response,
{HttpStatus: 400, errorCode: 390, errorType: OAuthException, errorMessage: There was a problem uploading your video file. Please try again.}
So, how do I go about sharing a video to Facebook?
I want to retrieve the facebook video mp4 URL and thumb images using the Facebook copy URL.I am getting 200 error for permissions while getting the video details. My code is given below.Please, anyone, help me to resolve this issue.
https://www.facebook.com/shreyaghoshal/posts/10155774118036484
request= GraphRequest.newMeRequest( AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object, GraphResponse response) {
try {
if(object!=null) {
create_facebookID = object.getString("id").toString();
Log.e("facebook" ,"id"+create_facebookID);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
create_facebookID+"_10155774118036484",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e("response", "res...." + response.toString());
}
}
).executeAsync();
}
}catch (Exception e){
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
this is the response I am getting. I want to get video URL.
10-31 10:04:45.203 27233-27233/com.tweak.tweak videos E/response: res....{Response: responseCode: 200, graphObject: {"created_time":"2017-10-09T09:12:56+0000","message":"I think I forgot how to breathe! Heart skipped beats. #PadmavatiTrailer is pure goosebumps. #SanjayLeelaBhansali has created the unthinkable.\nThe poetic magic that he alone can bring to the screens.Deepika Padukone Shahid Kapoor Ranveer Singh bring their best in this film! Music coming soon. Stay tuned.","the story":"Shreya Ghoshal shared Padmavati's video.","id":"11541726483_10155774118036484"}, error: null}
After so much time research.I got the solution. Now I can get the video details of the video. I Added keys for the bundle.Now I can get the video details.
if (Youtube_videos.fb_post_url) {
request_fb_post = new GraphRequest(
AccessToken.getCurrentAccessToken(),
create_facebookID + "_10155774118036484",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e("response", "res...." + response.toString());
}
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", "id,caption ,object_id ,permalink_url ,picture,source,status_type,properties,type ");
request_fb_post.setParameters(parameters);
request_fb_post.executeAsync();
I am new to android development. I am trying to post photo from an android app to user's facebook album. I added following code after I logged in the user with permissions "user_friends"
new GraphRequest(
MainFragment.mAccessToken.getCurrentAccessToken(),
"/me/photos",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
// This is my code for user login at app start
post = (Button)view.findViewById(R.id.button1);
mLoginManager = LoginManager.getInstance();
mLoginManager.registerCallback(mCallbackManager, mCallback);
mLoginManager.logInWithReadPermissions(this, Arrays.asList("user_friends")); //user_friends // publish_actions
Please guide me
I did a mistake .. Firstly, my question was incomplete .. I have found the issue .. Following seems to be working.
MainFragment.mLoginManager.logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
Bundle params = new Bundle();
params.putString("url", "http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg");
/* make the API call /
new GraphRequest(
MainFragment.mAccessToken.getCurrentAccessToken(),
"/me/photos",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/ handle the result */
Log.d("MainFragment:", "onCompleted mAccessToken = " + MainFragment.mAccessToken.getCurrentAccessToken());
}
}
).executeAsync();
I have successfully post a feed in facebook page form the graph api.
try {
resObj.put("message","feed from android");
//resObj.put("object_attachment",bitmap);
} catch (JSONException e) {
e.printStackTrace();
}
GraphRequest request = GraphRequest.newPostRequest(
AccessToken.getCurrentAccessToken(),"363453267193844/photos",resObj,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
Log.i(TAG,"post page response::"+graphResponse);
}
}
);
request.executeAsync();
But, I'm unable to post image into facebook page. The problem is I'm unable to find the key for image attachment in Json data posted in Graph Api.
The failed response from facebook is
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 324, errorType: OAuthException, errorMessage: (#324) Requires upload file}}
Finally, finally, I was able to post an image into facebook page. This is how I did to post an photo.
Bundle bundle=new Bundle();
bundle.putByteArray("object_attachment",byteArray);// object attachment must be either byteArray or bitmap image
bundle.putString("message","some message here");
GraphRequest graphRequest=new GraphRequest(AccessToken.getCurrentAccessToken(),
"{page_id}/photos",
bundle,
HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
Log.i("post page response::" + graphResponse);
}
);
graphRequest.executeAsync();
1.) Make sure you a page access token with publish_pages permission that can be used to publish new photos.
2.) From the docs . Note that you dont have a "/" before pageid in your call.
There are two separate ways of publishing photos to Facebook:
1: Attach the photo as multipart/form-data. The name of the object
doesn't matter, but historically people have used source as the
parameter name for the photo. How this works depends on the SDK you
happen to be using to do the post.
2: Use a photo that is already on the internet by publishing using the
url parameter:
Bundle params = new Bundle();
params.putString("url", "{image-url}");
/* make the API call */
new Request(
session,
"/{page-id}/photos",
params,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
There is no way to publish more then one photo in the same graph API
call.
3.) Example ==>
Try it like this i.e post byteArrayStream of your photo
postParams = new Bundle();
postParams.putString("message", "feed from android");
postParams.putBoolean("published",true);
String pageID = "363453267193844";
//Post to the page as the page user
ByteArrayOutputStream stream = new ByteArrayOutputStream();
<YOURBITMAPPHOTOHANDLE>.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
postParams.putByteArray("source", byteArray);
postParams.putString("access_token", "your_page_access_token");
/* make the API call */
new Request(
sessionInstance,
"/" + pageID + "/photos",
postParams,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
//An error occurred during posting to facebook
FacebookRequestError error = response.getError();
if (error != null) {
isPostingError = true;
postingErrorMessage = error.getErrorUserMessage();
} else {
isPostingError = false;
}
}
}
). executeAsync();