簡體   English   中英

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

[英]Sharing post using Facebook Graph API in Android

我正在嘗試在應用程序內部使用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. 您使用的SDK很舊, 強烈建議您更新到最新版本
  2. 您需要獲得Facebook批准所需的權限,請參閱此文檔
  3. 完成后,您需要通過“狀態和評論”標簽啟用應用
  4. 不應該一直向用戶詢問發布權限,而要說明為什么需要此權限,請參閱此處指南

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM