Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinkedInCommunicationFailed

Tags:

android

final LinkedInOAuthService oauthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(consumerKeyValue, consumerSecretValue);   
    LinkedInRequestToken requestToken = oauthService.getOAuthRequestToken();

I am using LinkedApi library,Yesterday this code was working but today I don't know why,but its giving exception

LinkedInRequestToken requestToken = oauthService.getOAuthRequestToken();

Its giving :

com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: https://api.linkedin.com/uas/oauth/requestToken
like image 998
Tofeeq Ahmad Avatar asked Apr 07 '26 03:04

Tofeeq Ahmad


1 Answers

--Solved-- I am posting code so all my friends need not to struggle

Step 1)Get pin by using API

oauthService= LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(consumerKeyValue, consumerSecretValue);   
    requestToken= oauthService.getOAuthRequestToken();
    //requestToken=oauthService.getOAuthRequestToken();
    //getOAuthRequestToken(""); 
    autoToken= requestToken.getToken();  
    authoTokenSecret = requestToken.getTokenSecret();  
    authUrl= requestToken.getAuthorizationUrl();
    Log.i("Tok", autoToken);
    Log.i("Tok", authoTokenSecret);
    Log.i("Tok", authUrl);

    webview.loadUrl(authUrl);

Step 2)webview will show pin after login to linked in now use your pin to got access token and using access token you can get profile and update status

String pin = pin_edit.getText().toString();
    System.out.println("Fetching access token from  LinkedIn...");        
    LinkedInAccessToken accessToken =  oauthService.getOAuthAccessToken(requestToken, pin);
    System.out.println("Access token: " +  accessToken.getToken());
    System.out.println("Token secret: " +  accessToken.getTokenSecret());
    final LinkedInApiClientFactory factory =  LinkedInApiClientFactory.newInstance(consumerKeyValue,  consumerSecretValue);
    final LinkedInApiClient client =  factory.createLinkedInApiClient(accessToken);

    Person profile = client.getProfileForCurrentUser();
    profile.setCurrentStatus("Hello all my friends ,I am missing you all"); 
    client.updateCurrentStatus("Hello all going");
like image 96
Tofeeq Ahmad Avatar answered May 05 '26 15:05

Tofeeq Ahmad