2016-01-07 13 views
1

我一直在使用LinkedIn mobile SDK成功地在我的應用LinkedIn本地應用程序。出錯的內容分享到LinkedIn

我能夠用我的應用程序成功登錄,但問題是與共享內容。雖然我成功登錄後,要在鏈接來分享我的內容,但它總是給我的錯誤響應

{ 
"errorCode": 0, 
"message": "Access to posting shares denied", 
"requestId": "MBB3L0G1KZ", 
"status": 403, 
"timestamp": 1452172936679 
} 

雖然我已經添加的所有權限LinkedIn enter image description here

我做了分享功能。

void shareImageOnLinkedIn() { 
    String shareJsonText = "{ \n" + 
      " \"comment\":\"" + "TalkingBookz" + "\"," + 
      " \"visibility\":{ " + 
      "  \"code\":\"anyone\"" + 
      " }," + 
      " \"content\":{ " + 
      "  \"title\":\"+audiobookinfo.title+\"," + 
      "  \"description\":\"+audiobookinfo.description+\"," + 
      "  \"submitted-url\":\"+audiobookinfo.sample_url+\"," + 
      "  \"submitted-image-url\":\"+audiobookinfo.cover_url+\"" + 
      " }" + 
      "}"; 

    // Call the APIHealper.getInstance method and pass the current context. 
    APIHelper apiHelper = APIHelper.getInstance(getApplicationContext()); 

    // call the apiHelper.postRequest with argument(Current context,url and content) 
    apiHelper.postRequest(BookdetailActivity.this, 
      shareUrl, shareJsonText, new ApiListener() { 

       @Override 
       public void onApiSuccess(ApiResponse apiResponse) { 

        Log.e("Response", apiResponse.toString()); 
        Toast.makeText(getApplicationContext(), "Shared Sucessfully", Toast.LENGTH_LONG).show(); 


       } 

       @Override 
       public void onApiError(LIApiError error) { 

        Log.e("Response", error.toString()); 
        Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show(); 
       } 
      }); 
} 

現在我在成功登錄響應後調用此函數。這裏,

LISessionManager.getInstance(getApplicationContext()).init(this, buildScope(), new AuthListener() { 
     @Override 
     public void onAuthSuccess() { 
      Log.e("Access Token :", LISessionManager.getInstance(getApplicationContext()).getSession().getAccessToken().toString()); 
      Toast.makeText(getApplicationContext(), "success" + LISessionManager.getInstance(getApplicationContext()).getSession().getAccessToken().toString(), Toast.LENGTH_LONG).show(); 
      shareImageOnLinkedIn(); 
     } 

     @Override 
     public void onAuthError(LIAuthError error) { 

      Log.v("Error", error.toString()); 

      Toast.makeText(getApplicationContext(), "failed " + error.toString(), 
        Toast.LENGTH_LONG).show(); 
     } 
    }, true); 

我試過一路解決,但我不能。所以請給出您的反饋或建議。提前的幫助將受到歡迎。

回答

3

最後我想通了什麼我已經錯過了。我的代碼是

private static Scope buildScope() { 
    return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS); 
} 

所以改爲

private static Scope buildScope() { 
    return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS, Scope.W_SHARE); 
} 

所以,現在它的工作非常細!

1

當你初始化LISessionManager,你傳遞一組您希望它使用的連接OAuth範圍的。在上面的示例代碼,這通過0​​方法,你沒有在你原來的問題包括髮生的,所以我真的不能確切知道......但我懷疑,即使你有你的LinkedIn應用程序配置爲請求w_share會員的權限,你是不是在做同樣的buildScope()過程,這將勝過任何值設置爲你的應用程序的配置默認值。

確保您buildScope()方法中包含了w_share成員權限的靜態值,例如:

private static Scope buildScope() { 
    return Scope.build(Scope.W_SHARE); 
} 
+0

謝謝配合。但實際上昨天我已經解決了我的問題。 – Piyush