varunoberoi / linkedin-j

Automatically exported from code.google.com/p/linkedin-j
0 stars 0 forks source link

Access to posting network updates denied. #119

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Trying to post network update using 
   LinkedInApiClient.postNetworkUpdate().
2. Throws LinkedInApiClientException: Access to posting network updates denied.
3.

What is the expected output? Should post update on LinkedIn.com 
What do you see instead? Exception

What version of the product are you using? 
On what operating system? Android

Please provide any additional information below.
Here's the logs
08-24 16:02:38.000: E/AndroidRuntime(2072): FATAL EXCEPTION: main
08-24 16:02:38.000: E/AndroidRuntime(2072): 
com.google.code.linkedinapi.client.LinkedInApiClientException: Access to 
posting network updates denied.
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.createLinkedInApiC
lientException(BaseLinkedInApiClient.java:3906)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.callApiMethod(Base
LinkedInApiClient.java:3846)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.postNetworkUpdate(
BaseLinkedInApiClient.java:1172)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
pl.osadkowski.LITest.LITestActivity.onNewIntent(LITestActivity.java:64)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1119)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.app.ActivityThread.deliverNewIntents(ActivityThread.java:1697)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.app.ActivityThread.performNewIntents(ActivityThread.java:1709)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.app.ActivityThread.handleNewIntent(ActivityThread.java:1717)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.app.ActivityThread.access$2300(ActivityThread.java:117)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:975)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.os.Looper.loop(Looper.java:123)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
android.app.ActivityThread.main(ActivityThread.java:3647)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
java.lang.reflect.Method.invokeNative(Native Method)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
java.lang.reflect.Method.invoke(Method.java:507)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-24 16:02:38.000: E/AndroidRuntime(2072):     at 
dalvik.system.NativeStart.main(Native Method)

Original issue reported on code.google.com by narendra...@gmail.com on 24 Aug 2012 at 10:39

GoogleCodeExporter commented 9 years ago
once check consumer key and consumer secret keys properly

Original comment by kres...@gmail.com on 29 Aug 2012 at 10:42

GoogleCodeExporter commented 9 years ago
I'm using the right keys and secret. Actually I'm able to update the status of 
the profile but the above exception comes only when I'm trying to post some 
network updates. 

Original comment by narendra...@gmail.com on 29 Aug 2012 at 11:07

GoogleCodeExporter commented 9 years ago
I proposed these two changes to the implementation to solve the problems 
encountered with scope...

1.
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>LinkedInOAuthService.java (Today 18.48.21)</html>
+++ <html>LinkedInOAuthService.java (Today 18.54.32)</html>
@@ -51,6 +51,15 @@
      * 
      * @return the o auth access token
      */
+    public LinkedInAccessToken getOAuthAccessToken(LinkedInRequestToken 
requestToken, String scope, String oauthVerifier);
+    /**
+     * Gets the o auth access token.
+     * 
+     * @param requestToken the request token
+     * @param oauthVerifier the oauthVerifier
+     * 
+     * @return the o auth access token
+     */
     public LinkedInAccessToken getOAuthAccessToken(LinkedInRequestToken requestToken, String oauthVerifier);

     /**

2.

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>LinkedInOAuthServiceImpl.java (Today 18.48.21)</html>
+++ <html>LinkedInOAuthServiceImpl.java (Today 18.59.30)</html>
@@ -115,12 +115,20 @@
      */
     @Override
     public LinkedInAccessToken getOAuthAccessToken(LinkedInRequestToken requestToken, String oauthVerifier) {
+        return(getOAuthAccessToken(requestToken, null, oauthVerifier));
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public LinkedInAccessToken getOAuthAccessToken(LinkedInRequestToken 
requestToken, String scope, String oauthVerifier) {
        if (requestToken == null) {
            throw new IllegalArgumentException("request token cannot be null.");
        }
         try {
            final OAuthConsumer consumer = getOAuthConsumer();
-           final OAuthProvider provider = getOAuthProvider();
+           final OAuthProvider provider = getOAuthProvider(scope);

            consumer.setTokenWithSecret(requestToken.getToken(), requestToken.getTokenSecret());
             provider.retrieveAccessToken(consumer, oauthVerifier);
@@ -227,7 +235,13 @@
      *
      */
     protected OAuthProvider getOAuthProvider() {
-       DefaultOAuthProvider provider = new 
DefaultOAuthProvider(LinkedInApiUrls.LINKED_IN_OAUTH_REQUEST_TOKEN_URL,
+        return(getOAuthProvider(null));
+    }
+    /** 
+     *
+     */
+    protected OAuthProvider getOAuthProvider(String scope) {
+       DefaultOAuthProvider provider = new 
DefaultOAuthProvider(LinkedInApiUrls.LINKED_IN_OAUTH_REQUEST_TOKEN_URL+(scope!=n
ull)?"?scope="+scope.replace(' ', '+'):"",
                LinkedInApiUrls.LINKED_IN_OAUTH_ACCESS_TOKEN_URL, LinkedInApiUrls.LINKED_IN_OAUTH_AUTHORIZE_URL);

        provider.setOAuth10a(OAUTH_VERSION_1_0_a.equals(ApplicationConstants.OAUTH_VERSION));

Then use  instead of simply:
       LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(linkedInApiKey, linkedInSecretKey)
       LinkedInRequestToken requestToken = oauthService.getOAuthRequestToken(callbackUrl);

      LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(linkedInApiKey, linkedInSecretKey)
       LinkedInRequestToken requestToken = oauthService.getOAuthRequestToken(callbackUrl, scope);

The scope is defined with a string like (See 
http://oodlestechnologies.com/blogs/Recent-changes-in-LinkedIn-API for more 
info)
scope = "r_fullprofile r_network";

Hopes it helps
  Thierry Bodhuin

Original comment by bodh...@gmail.com on 15 Sep 2012 at 5:12

GoogleCodeExporter commented 9 years ago
hi i am using java now how to use scope ...for linkedin

Original comment by prash...@cloudcodes.com on 28 Sep 2012 at 8:32