向LinkedIn分享内容时遇到错误

时间:2016-01-07 13:29:55

标签: android linkedin linkedin-api

我已使用LinkedIn mobile SDK在我的应用程序中成功集成了LinkedIn本机应用程序。

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

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

我一直试图解决但我无法解决。所以请提供您的反馈或建议。提前帮助将受到关注。

2 个答案:

答案 0 :(得分: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 :(得分:1)

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

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

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