【问题标题】:Error on sharing the content to LinkedIn将内容分享到 LinkedIn 时出错
【发布时间】:2016-01-08 13:36:38
【问题描述】:

我已经使用LinkedIn mobile SDK成功地将LinkedIn本机应用程序集成到我的应用程序中。

我可以使用我的应用程序成功登录,但问题在于共享内容。当我成功登录时,想将我的内容分享给 Linked in 但它总是给我错误响应

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

虽然我已将所有权限添加到 LinkedIn

我做了分享功能。

 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);

我已经尝试了各种方法来解决,但我不能。因此,请提供您的反馈或建议。我们会提前获得帮助。

【问题讨论】:

    标签: android linkedin linkedin-api


    【解决方案1】:

    我终于弄清楚我错过了什么。我的代码是

    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);
    }
    

    所以现在它工作得很好!!

    【讨论】:

      【解决方案2】:

      当您初始化 LISessionManager 时,您向其传递一组您希望它用于连接的 OAuth 范围。在您上面的示例代码中,这是通过您未包含在原始问题中的 buildScope() 方法发生的,因此我无法确定...但我怀疑即使您将 LinkedIn 应用程序配置为请求w_share 成员权限,您在 buildScope() 进程中的做法不同,这将胜过您在应用配置中设置为默认值的任何值。

      确保您的 buildScope() 方法包含 w_share 成员权限的静态值,例如:

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

      【讨论】:

      • 谢谢伙计。但实际上昨天我已经解决了我的问题。
      猜你喜欢
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多