ajay154 / linkedin-j

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

Linkedin has changed the implementation and now this is not working , cannot post status it #118

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Linkedin has changed the implementation and now the posting of the status is 
not working , when i try to post the status it gives 403 (forbidden) error , i 
have read some blog , it require premisiion  r_basicprofile
rw_nus , how to set them in this jar , Please do answer i have searched it all .

Original issue reported on code.google.com by saad.sal...@gmail.com on 23 Aug 2012 at 10:18

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