问题
i'm developing a simple android app and i want post a status in facebook using OpenGraphObject and OpenGraphAction.
if i use new FacebookDialog.ShareDialogBuilder(this)
i have no problem, but when i'm using FacebookDialog.OpenGraphActionDialogBuilder
i got the error:
01-09 15:56:29.594 11439-11439/simov.project2.yourcity E/Activity﹕ Error: com.facebook.FacebookException: Failed to generate preview for user.
java
public void test(int position){
File f = (File)mImageAdapter.getItem(position);
Bitmap myBitmap= BitmapFactory.decodeFile(f.getAbsolutePath());
List<Bitmap> images = new ArrayList<Bitmap>();
images.add(myBitmap);
//Session session = Session.getActiveSession();
//session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSION));
try {
addresses = mGeocoder.getFromLocation(mItenerariumState.getCurrentLocation().getLatitude()
, mItenerariumState.getCurrentLocation().getLongitude()
, 1);
} catch (IOException e) {
e.printStackTrace();
}
OpenGraphObject location = OpenGraphObject.Factory.createForPost("yourcity:location");
if(!addresses.isEmpty()){
location.setProperty("title", addresses.get(0).getAddressLine(0));
} else {
location.setProperty("title", "Unknown place");
}
location.setProperty("Description", "I visited this place using YourCity App");
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("location", location);
/* Request request = Request.newPostOpenGraphActionRequest(Session.getActiveSession(), action, new Request.Callback() {
@Override
public void onCompleted(Response response) {
//showPublishResult(getString(R.string.photo_post), response.getGraphObject(), response.getError());
}
});
request.executeAsync();*/
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "yourcity:visit","location")
.setApplicationName("YourCity")
//.setImageAttachmentsForAction(images, true)
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
Important note, the shareDialog show in the screen by like one second and then disappears without any action
回答1:
Have been dealing with this error for hours. Heres how I fixed it. The Actions and Objects you specified in your code are the ones that cause the problem.
The samples provided on the Facebook developers guide aren't good enough I feel. Heres a sample code you can use that will work perfectly. Basically make sure your ObjectType -> eg: video.other is set correctly and your Action type e.g: video.watches is set right.
void sometestCode(){
OpenGraphObject video = OpenGraphObject.Factory.createForPost("video.other");
video.setTitle("Awesome Video");
video.setDescription("This video will show you how to make the Opengraph work");
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("video", video);
action.setType("video.watches");
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "video")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
回答2:
We had the exact same error some times ago. Check you are using the correct action type in OpenGraphActionDialogBuilder. We fixed the same error just using the correct action type parameter. In your case you should check if "yourcity:visit" is the name of the action. Go to developer consolle https://developers.facebook.com/x/apps/your-app-id/open-graph/action-types/ and click on Get Code for the action you want to implement. Then read the url that should looks like something like this:
https://graph.facebook.com/me/app_namespace:app_action?...
then use the correct app_action in your code. It should fix!
来源:https://stackoverflow.com/questions/21025174/android-facebook-sdf-exception-failed-to-generate-preview-for-user