sandeshdate / linkedin-j

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

How to set scope in requestToken from linkedin-j? #120

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I've done just same as per the Wiki of linkedin-j for getting Network 
UPDATES of any user.

I see that when ever I make the client to go for AuthorizationURL then they are 
only prompted to allow access for Basic Information of the user. But I would 
like them to allow is their network updates too. How can we do that?

Code Part
============
// the getLinkedInOAuthServiceInstance() provides the object of 
LinkedInOAuthService using 
// the code of 
LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(API_KEY, 
SECRET_KEY);

if(requestToken == null)requestToken = 
getLinkedInOAuthServiceInstance().getOAuthRequestToken();       
String authUrl = requestToken.getAuthorizationUrl();
System.out.println(authUrl);
//I get the pin code of the user in "pin" variable
LinkedInAccessToken accessToken = 
oauthService.getOAuthAccessToken(requestToken, pin);
final LinkedInApiClientFactory factory = 
LinkedInApiClientFactory.newInstance(API_KEY, SECRET_KEY);
client = factory.createLinkedInApiClient(accessToken);
Network network = 
client.getNetworkUpdates(EnumSet.of(NetworkUpdateType.SHARED_ITEM));
================

Now I get exception like this:
----------------------------------------------------------

Exception in thread "main" 
com.google.code.linkedinapi.client.LinkedInApiClientException: Access to 
network denied
    at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.createLinkedInApiClientException(BaseLinkedInApiClient.java:3906)
    at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.callApiMethod(BaseLinkedInApiClient.java:3781)
    at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.callApiMethod(BaseLinkedInApiClient.java:3725)
    at com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.getNetworkUpdates(BaseLinkedInApiClient.java:702)
    at socialfeed.linkedin.LinkedInConnector.getPosts(LinkedInConnector.java:70)
    at socialfeed.linkedin.LinkedInConnector.main(LinkedInConnector.java:166)

Thanks in advance.

Original issue reported on code.google.com by ngmm...@gmail.com on 1 Sep 2012 at 10:55

GoogleCodeExporter commented 8 years ago
I am also getting the error message "Access to network denied" and "Access to 
people search denied". 

How to set the scope in the request token URL to solve this problem?

Original comment by goel.anu...@gmail.com on 11 Sep 2012 at 1:12

GoogleCodeExporter commented 8 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 8 years ago
please resolve this m waiting for this

Original comment by deepakch...@gmail.com on 28 Sep 2012 at 10:46

GoogleCodeExporter commented 8 years ago
I've solved this issue before couple of weeks. Sorry for my late response. I've 
posted my answer at here. 
http://stackoverflow.com/questions/12188341/cant-post-anything-on-linkedin-using
-linkedin-j/12565935#12565935

Thanks

Original comment by ngmm...@gmail.com on 28 Sep 2012 at 2:17

GoogleCodeExporter commented 8 years ago
Hi Thanks for reply, it would be appreciated if you provide one method to
set request parameter in linkedin-j. Your lib very good m looking for some
positive response.

Original comment by deepakch...@gmail.com on 29 Sep 2012 at 12:56

GoogleCodeExporter commented 8 years ago
Another patch you can do without compile the code is to change the final field 
via reflection, here is the example:
            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");

Original comment by cont...@donanza.com on 25 Apr 2013 at 9:56

GoogleCodeExporter commented 8 years ago
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
  <status>403</status>
  <timestamp>1369385621393</timestamp>
  <request-id>79TGO06QXQ</request-id>
  <error-code>0</error-code>
  <message>Access to people search denied.</message>
</error> 

I get this results when I try to access the people search using REST apis in 
Client REST Simple, so how do we solve this error , all the apis work for 
example jobs and companies api works perfectly for me but This doesnt work can 
anyone provide me the solution and suggestion on this issue.Thanks Vishal.

Original comment by vishalb...@gmail.com on 24 May 2013 at 9:24

GoogleCodeExporter commented 8 years ago
Hi ngmm..,

Thanks a lot.

Original comment by alok....@gmail.com on 1 Aug 2013 at 9:49

GoogleCodeExporter commented 8 years ago
use this http://db.tt/yQjhqeq3 patched linkedin-j library and refer to this 
link for usage http://stackoverflow.com/a/13510881

Original comment by rbprakas...@gmail.com on 8 Aug 2013 at 11:20

GoogleCodeExporter commented 8 years ago
how to get all types of network update ? Not just SHARED_ITEM or STATUS_UPDATE ?

Original comment by psagg...@gmail.com on 27 Jan 2014 at 8:38