Error on sharing the content to LinkedIn

放肆的年华 提交于 2019-12-08 01:50:11

问题


I have successfully integrated LinkedIn native application in my application using LinkedIn mobile SDK.

I am able to login successfully with my application but the problem is with sharing the content. While I successfully logged in , want to share my content to Linked in but it always give me error response

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

though i have added all permission to LinkedIn

I have made share function.

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

Now I am calling this function after successfull login response. Here,

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

I have tried all the way to solve but i couldn't. So please give your feedback or suggestion. Advance help would be appriciated.


回答1:


Finally I have figured out what i have missed. My code was

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

So changed to

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

So now its working very fine !!




回答2:


When you initialize your LISessionManager, you pass it a set of OAuth scopes that you want it to use for the connection. In your sample code above, this happens via the buildScope() method that you did not include in your original question, so I can't really know for sure ... but I suspect that even though you have your LinkedIn app configured to request the w_share member permission, you are not doing the same in the buildScope() process, which will trump whatever values you set as defaults in your app's config.

Ensure your buildScope() method contains the static value for the w_share member permission, e.g.:

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


来源:https://stackoverflow.com/questions/34656390/error-on-sharing-the-content-to-linkedin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!