【发布时间】:2016-06-21 11:08:10
【问题描述】:
我会在我的应用程序中创建一个带有照片和标题的帖子,然后将其发布到我的 Facebook 上。 我不确切知道所需的步骤,所以我不知道我做错了什么。 主要活动在其 xml 中有一个 LoginButton 和一个 ShareButton。 我做到了:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
public DBhelper database;
public CallbackManager callbackManager;
public ShareDialog shareDialog;
public ShareButton shareButton;
public SharePhotoContent sharePhotoContent;
}
这个类有:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
shareButton=new ShareButton(this);
setContentView(R.layout.activity_main);
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends","public_profile");
get_login_details(loginButton);
shareButton=(ShareButton) findViewById(R.id.share_button);
sharePhotoContent=genera_share_photo_content();
shareButton.setShareContent(sharePhotoContent);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode,resultCode,data);
Log.e(TAG,data.toString());
}
还有这两种方法:
protected void get_login_details(LoginButton loginButton) {
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Toast.makeText(getApplicationContext(),"SI",Toast.LENGTH_LONG).show();
}
@Override
public void onCancel() {
// App code
Toast.makeText(getApplicationContext(),"CANCEL",Toast.LENGTH_LONG).show();
}
@Override
public void onError(FacebookException exception) {
// App code
Toast.makeText(getApplicationContext(),"NO",Toast.LENGTH_LONG).show();
}
});
}
public SharePhotoContent genera_share_photo_content() {
//code...
Bitmap image = ...
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
return content;
}
现在,共享内容是在开头制作的:我会使用genera_share_photo_content() 使其动态化:
我要如何修改它?
我应该打电话给shareDialog.show(content) 还是ShareApi.share(content,null)?
是我为登录按钮设置的权限user_friends 和public_profile。足以使所有工作?
【问题讨论】:
标签: android facebook share photo