Reputation: 18933
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.
Upvotes: 2
Views: 828
Reputation: 18933
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 !!
Upvotes: 3
Reputation: 3374
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);
}
Upvotes: 1