Proxy Issue for LinkedIn #338

Closed
gaoming626 opened this Issue Dec 18, 2012 · 1 comment

Projects

None yet

2 participants

When there is no proxy, the Linkedin example works fine.

When there is a proxy, i got an error:

=== LinkedIn's OAuth Workflow ===

Fetching the Request Token...
Exception in thread "main" org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: '<script type="text/javascript">
window.onload = function()
{
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++)
{
var fields = cookies[i].split('=');
if (fields.length == 2)
{
var name = fields[0].replace(/\s/g, '');
if (name == 'denial-reason-code')
{
var reasonCodes = 'Reason codes: ' + fields[1] + '
';
document.getElementById('denialInfo').innerHTML += reasonCodes;
}
if (name == 'denial-client-ip')
{
var ip = 'IP: ' + fields[1] + '
';
document.getElementById('denialInfo').innerHTML += ip;
}
}
}
}
</script>

<title>999: request failed</title>
  <link rel="stylesheet" type="text/css" href="http://www.linkedin.com/scds/concat/common/css?h=9z3sq2jihmaimdbx7j4cn6odq">
LinkedIn

Request denied

Sorry, we are unable to serve your request at this time due to unusual traffic from your network connection.

Please visit our help page and provide the information below for further assistance.


' at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41) at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27) at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:52) at com.avaya.smm.linkedin.LinkedInExample.main(LinkedInExample.java:83)

My test example is like following:

package com.avaya.smm.linkedin;
import java.util.Scanner;

import org.scribe.builder.;
import org.scribe.model.
;
import org.scribe.oauth.*;
public class LinkedInExample
{
// private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)";
private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections";

// private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/mailbox";
public static void main(String[] args)
{

  System.setProperty("https.proxyHost", "co.proxy.avaya.com");
  System.setProperty("https.proxyPort", "8000");

OAuthService service = new ServiceBuilder()
                            .provider(LinkedInApiWithScope.class)
                            .apiKey("n83uklxjywh6")
                            .apiSecret("fTePpVvEuRHHhiMd")
                            .build();

Scanner in = new Scanner(System.in);

System.out.println("=== LinkedIn's OAuth Workflow ===");
System.out.println();

// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();

System.out.println("Got the Request Token!");
System.out.println();

System.out.println("Now go and authorize Scribe here:");
System.out.println(service.getAuthorizationUrl(requestToken));

System.out.println("And paste the verifier here");

System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());

System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");

//get all the headers
System.out.println("Request headers: " + request.getHeaders().toString());
System.out.println("Response headers: " + response.getHeaders().toString());

// get the url requested
System.out.println("Original location is: " + request.getHeaders().get("content-location"));

// Date of response
System.out.println("The datetime of the response is: " + response.getHeader("Date"));

// Format of the reponse
System.out.println("Format is: " + response.getHeader("x-li-format"));

// Content-type of the response
System.out.println("Content type is: " + response.getHeader("Content-Type") + "\n\n");

}

}

Collaborator

Configure the proxy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment