0
我會在我的應用程序中創建一張帶有照片和標題的帖子,並將其張貼在我的臉書上。 我不知道所需的步驟,所以我不知道我做錯了什麼。 主要活動在其xml中有一個LoginButton和一個ShareButton。 我所做的:張貼照片facebook android
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;
}
現在,共享內容在開始時maked:我想使它成爲動態使用genera_share_photo_content()
: 我怎樣才能修改它,當我想要什麼? 我應該打電話shareDialog.show(content)
還是ShareApi.share(content,null)
? 權限user_friends
和public_profile
,我設置爲登錄按鈕。足以使所有工作?
我如何添加該權限?使用LoginButton.setReadPermission()或LoginButonn.setPublishPermissions()? – SctALE
在代碼中替換此行:'loginButton.setReadPermissions(「user_friends」,「public_profile」);''with'loginButton.setReadPermissions(「publish_actions」);' – Ashwani
閱讀此博客,它將幫助您理解:http:// simpledeveloper.com/how-to-share-an-image-on-facebook-in-android/ – Ashwani