Can't post anything on LinkedIN using linkedin-j
Asked Answered
L

5

9

First, my problem is that I can't post any Network Updates, post Shares or Invite by ID. I always get the following exception :

08-29 17:18:04.000: E/AndroidRuntime(4316): FATAL EXCEPTION: main
08-29 17:18:04.000: E/AndroidRuntime(4316): com.google.code.linkedinapi.client.LinkedInApiClientException: Access to posting network updates denied.
08-29 17:18:04.000: E/AndroidRuntime(4316):     at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.createLinkedInApiClientException(BaseLinkedInApiClient.java:3906)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.callApiMethod(BaseLinkedInApiClient.java:3846)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.postNetworkUpdate(BaseLinkedInApiClient.java:1172)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at pl.osadkowski.LITest.LITestActivity.onNewIntent(LITestActivity.java:61)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1123)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2042)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.app.ActivityThread.performNewIntents(ActivityThread.java:2055)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2064)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.app.ActivityThread.access$1400(ActivityThread.java:123)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1194)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.os.Looper.loop(Looper.java:137)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at android.app.ActivityThread.main(ActivityThread.java:4424)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at java.lang.reflect.Method.invokeNative(Native Method)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at java.lang.reflect.Method.invoke(Method.java:511)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-29 17:18:04.000: E/AndroidRuntime(4316):     at dalvik.system.NativeStart.main(Native Method)

Secondly, What have I tried? Well, I'm sure I haven't tried EVERYTHING or else it would be working but I feel like I exhausted all possibilities. SOME of the things I have tried to no avail :

https://developer.linkedin.com/documents/authentication#granting

https://mcmap.net/q/1314334/-posting-linkedin-message-from-android-application

http://code.google.com/p/linkedin-j/source/browse/trunk/linkedin-j/core/src/examples/java/com/google/code/linkedinapi/client/examples/PostNetworkUpdateExample.java?r=197

http://code.google.com/p/linkedin-j/wiki/GettingStarted

http://code.google.com/p/linkedin-j/wiki/AndroidConfiguration

I really hope someone can help!! I'll try anything!! Thanks a million!

Libration answered 30/8, 2012 at 0:29 Comment(0)
D
9

I made a fix for scope parameter to linkedin-j-android.jar of version 1.0.429

here is the link for downloading patched linkedin-j-android.jar with scope fix

http://db.tt/yQjhqeq3

and Usage is like this it is additional parameter

private String CONSUMER_KEY="XX"; // your consumer key here
private String CONSUMER_SECRET="YY"; // your consumer secret here
private String scopeParams="rw_nus+r_basicprofile";

LinkedInOAuthService oAuthService=LinkedInOAuthServiceFactory
            .getInstance().createLinkedInOAuthService(
                    CONSUMER_KEY,CONSUMER_SECRET, scopeParams);

Hope this helps..

Dodecasyllable answered 22/11, 2012 at 10:39 Comment(7)
Replace "rw_nus+r_baseprofile" with "rw_nus+r_basicprofile" and it will work. cheers!!Kimon
Thank you very much! Worked like a charm :)Libration
user2012, Ashok i have used your code but in my code i don't allow to pass three string i can pass only two string in parameter! can you help me?Personalism
@user2012 had you replaced linkedin-j-android.jar from db.tt/yQjhqeq3 and then triedDodecasyllable
@Dodecasyllable : No dude i didn't replaced the LinkedIn jar file rather I just pass the required scopes as parameter as you described above.Kimon
i used it and got error msg com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null. i think coz of this line LinkedinDialog.liToken = LinkedinDialog.oAuthService .getOAuthRequestToken(Config.OAUTH_CALLBACK_URL); help plzHahn
Hi , I am facing issue at Login click after adding "scopeParams" in oAuthService params , "com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: api.linkedin.com/uas/oauth/…" Without adding this , i am successfully able to logged in but then even after getting '"Success" in sharing post, the post is not being shared to LinkedInEstrogen
W
2

You don't have to change the source code. you can change the URL via reflection:

java.lang.reflect.Field field = LinkedInApiUrls.class.getField("LINKED_IN_OAUTH_REQUEST_TOKEN_URL");
field.setAccessible(true);
java.lang.reflect.Field modifiersField = java.lang.reflect.Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, LinkedInApiUrls.LINKED_IN_OAUTH_REQUEST_TOKEN_URL + "?scope=r_basicprofile+r_emailaddress");

Anyhow, LinkedIn oAuth1 API doesn't support getting the email, you must use the oAuth2 API (http://developer.linkedin.com/documents/authentication)

Warta answered 25/4, 2013 at 9:57 Comment(0)
S
1

I'm getting same problem too. I see that my requestToken doesn't ask permission for network updates to user. So I'm not able to get the Network Updates.

But where is that assigning scope part in api of linkedin-j? I looked over the linkedin api and got that we must use scope=rw_nus+r_basicprofile param in requestToken.

Stump answered 1/9, 2012 at 10:45 Comment(2)
are you sure you tried using http://[linked_in_request_token_url]?scope=rw_nus+r_basicprofileStump
can you tell me how to recreate the executable jar file after editing ?Kimon
N
1

I fixed the issue by using scribe.jar instead of linkedin-j.jar. You have to extract the classes in the jar and edit org.scribe.builder.api.LinkedInApi.class to change the url "https://api.linkedin.com/uas/oauth/requestToken" to "https://api.linkedin.com/uas/oauth/requestToken?scope=rw_nus".

You can achieve this by deleting the class LinkedInApi from the package and then repackage the scribe.jar file. And, create a file with the same name in the same package in your project by changing the url. You can get the .java version of the file in the location "https://github.com/fernandezpablo85/scribe-java/blob/master/src/main/java/org/scribe/builder/api/LinkedInApi.java".

This is to add the permission for making network updates when requesting permission from the user. The xml for sending the input for the network update is given in the link "https://developer.linkedin.com/documents/share-api"

Norby answered 12/9, 2012 at 9:20 Comment(0)
S
1

@eddy, Simple workaround is download the src jar of the linked-j and then find LinkedInApiUrls.properties and finally edit the property : "com.google.code.linkedinapi.client.oauth.requestToken" with https://api.linkedin.com/uas/oauth/requestToken?scope=rw_nus+r_basicprofile

then add that edited src code to your project as library.

Stump answered 24/9, 2012 at 13:21 Comment(2)
can you tell me how to recreate the executable jar file after editing ?Kimon
@user2012. If you have the source of JAR. Create a project in eclipse of this source. Do changes what you want and export that project as JAR in eclipse.;Aphonic

© 2022 - 2024 — McMap. All rights reserved.