我正在开发一个Android应用程序,它在特定活动中截取屏幕截图并在Facebook上为用户发布(FacebookSDK)。
第一次,它询问用户权限,要求登录并指定视图(Public,Friends ..等)。当下次再次调用该活动时,它表示像"您已经授权App"然后单击确定后直接发布图片。
问题是:
请帮忙。
代码:
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
List<String> permissionNeeds = Arrays.asList("publish_actions");
//this loginManager helps you eliminate adding a LoginButton to your UI
manager = LoginManager.getInstance();
manager.logInWithPublishPermissions(this, permissionNeeds);
manager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
shareOnFacebook();
}
@Override
public void onCancel() {
Toast.makeText(HallOfFame.this, "Cancelled",Toast.LENGTH_LONG).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(HallOfFame.this, "Error Occurred",Toast.LENGTH_LONG).show();
}
});
return true;
方法shareOnFacebook:
// Take Screenshot
View rootView = findViewById(android.R.id.content).getRootView();;
rootView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(rootView.getDrawingCache());
//**Bitmap bitmap = rootView.getDrawingCache();
rootView.setDrawingCacheEnabled(false);
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bitmap)
.setCaption("Hey Guys..! Checkout my Awesome Pic.")
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
ShareApi.share(content, null);
manager.logOut();
// this.finish();
// this.onDestroy();
// FacebookSdk.clearLoggingBehaviors();