在Android中使用Facebook Graph API分享帖子

时间:2015-08-13 13:49:25

标签: android facebook facebook-graph-api share

我正在尝试使用我的应用程序内的Facebook API分享帖子,我在Facebook Developer上创建了一个帐户,我将应用程序ID放在应用程序中,登录过程工作正常,如果我分享了开发者Facebook的帖子帐户,每件事都很好。但是,当我尝试使用任何其他Facebook帐户分享时,我什么都没有共享。 我正在使用Facebook SDK 3.5及以下版本的共享代码:

 /**
 * Post message with image
 * 
 * @param imageURl
 */
public void postStatusMessage( byte [] imageURl ) {
    if ( checkPermissions( Session.getActiveSession() ) ) {
        final CustomProgressDialog progress = new CustomProgressDialog( FBActivity.this ) ;
        progress.show() ;

        // Filling the needed data for the share
        Bundle parameters = new Bundle() ;
        parameters.putString( "message" , shareText.getText().toString() ) ; // message
        parameters.putString( "description" , name ) ;// description
        parameters.putString( "link" , linkUrl ) ;// link if available
        parameters.putByteArray( "picture" , imageURl ) ;// byte array for the image so it can be shared as image not as link

        Request.Callback callback = new Request.Callback() {
            public void onCompleted( Response response ) {
                if ( response.getError() == null ) {
                    // Share post was done succesfully
                    Toast.makeText( FBActivity.this , getString( R.string.statusUpdateSucc ) , Toast.LENGTH_LONG ).show() ;
                    onlineActionID = ( String ) response.getGraphObject().getProperty( "id" ) ;
                    shareSuccesfuly = true ;

                } else {
                    // Fail in share
                    Toast.makeText( FBActivity.this , "" + getString( R.string.statusUpdateFail ) , Toast.LENGTH_LONG ).show() ;

                }
                // Dismiss progress dialog
                if ( progress.isShowing() )
                    progress.dismiss() ;

                // if share was done sucessfully , navigate back to the previvos page
                if ( shareSuccesfuly ) {
                    finish() ;
                }// end if.
                else {
                    finish() ;
                }// end else().
            }
        } ;

        // Request should have the me/photos tag so we can share photos in the user profile
        Request request = new Request( Session.getActiveSession() , "me/photos" , parameters , HttpMethod.POST , callback ) ;

        request.executeAsync() ;
    } else {
        requestPermissions() ;
    }
}

1 个答案:

答案 0 :(得分:1)

  1. 您使用的SDK已经很老了,我强烈建议您更新到最新版本
  2. 您需要获得Facebook批准所需的权限,请参阅此doc
  3. 完成后,您需要在状态和状态下生成应用。审核标签
  4. 不应该继续向用户询问发布权限,而是说明为什么需要这样做,请参阅guidelines here