Using oauth ... error 401 - Token invalid - Invalid AuthSub token

36 views
Skip to first unread message

alucarD

unread,
Aug 23, 2010, 4:42:46 PM8/23/10
to google-api-java-client
Hi
I use dyuproject to implement hybrid (openid+oauth). So I have token
secret and token key. How I can use this information to sign
requests ? This is code that produce error 401 - Token invalid -
Invalid AuthSub token.

HttpTransport transport =
GoogleTransport.create();
GoogleHeaders headers = (GoogleHeaders)
transport.defaultHeaders;
headers.setApplicationName("google-youtubejsoncsample-1.0");
headers.gdataVersion = "2";
transport.addParser(new JsonCParser());

OAuthHmacSigner signer = new OAuthHmacSigner();
signer.clientSharedSecret =
"shared_secret_from_registration_domain";
signer.tokenSharedSecret =
"token_shared_secret_from_dyuproject_oauth";
OAuthParameters authorizer = new OAuthParameters();
authorizer.consumerKey = "myapp.appspot.com";
authorizer.signer = signer;
authorizer.token = "token_secret_fromdyuproject_oauth";
authorizer.signRequestsUsingAuthorizationHeader(transport);


YouTubeUrl url = YouTubeUrl.relativeToRoot("videos");
url.maxResults = 5;
url.author = "searchstories";
// execute GData request for the feed
VideoFeed feed = VideoFeed.executeGet(transport, url);
System.out.println("Total number of videos: " +
feed.totalItems);
for (Video video : feed.items) {
Log.info("");
Log.info("-----------------------------------------------");
Log.info("Video title: " + video.title);
Log.info("Description: " + video.description);
Log.info("Updated: " + video.updated);
Log.info("Tags: " + video.tags);
Log.info("Play URL: " + video.player.defaultUrl);
}


Please help. When I comment my signing code then request to youtube
service works excellent.

alucarD

unread,
Aug 24, 2010, 6:04:00 AM8/24/10
to google-api-java-client
Is there any posibility that google api java client dont work on
google app engine (java)?

Yaniv Inbar (יניב ענבר)

unread,
Sep 2, 2010, 5:23:45 PM9/2/10
to google-api-...@googlegroups.com
Sorry for the slow response, but without more details I cannot really help diagnose the problem.

Google App Engine Java is fully supported by the Google API Java Client library, so that's shouldn't an issue.

Unfortunately, OAuth 401 errors can sometimes be difficult to diagnose.  Sometimes there is a cryptic error message that nonetheless is a key to understanding what failed.  The easiest way to start to debug this is by enabling logging of requests and responses:

      Logger logger = Logger.getLogger("com.google.api.client");
      logger.setLevel(Level.ALL);

Notice that I set logging level to Level.ALL in order to also log the Authorization header.  If you use logging level CONFIG it won't show you the Authorization header.

You can see your logged messages in the "Logs" page on your App Engine dashboard.  Let me know if that helps.

--
Yaniv Inbar
Senior Software Engineer
Google Inc.

Roberto Manicardi

unread,
Sep 17, 2010, 1:37:54 AM9/17/10
to google-api-java-client
Hi,

are you writing a Desktop or a Web application?


In the first case I found very useful this example:

http://code.google.com/p/gdata-java-client/source/browse/branches/2/sample/discovery/discovery-sample/src/com/google/api/client/sample/discovery/DiscoverySample.java?r=436#313

You can also try if your client key and client secret are working fine
using Oauth playgorund

http://googlecodesamples.com/oauth_playground/

HTH,
Roberto
Reply all
Reply to author
Forward
0 new messages