3-legged OAuth .NET C# - I have my tokens, now how to use them with this client library ?!?!?!

1,157 views
Skip to first unread message

Shane

unread,
Nov 23, 2010, 4:19:40 PM11/23/10
to Google Data APIs .NET Client Library
So I have spent WAY too much time on this problem and I am hoping
someone can help me out here.

I have been successful in getting my 3-Legged OAuth credentials
using .Net and C# from Google. I works well and have my AccessToken

I have:

Consumer_Key
Consumer_Secret
Token
Token_Secret


Now the question is: How to I make a call to GData services using this
information in the .Net Client library from Google? I can't figure it
out.

http://code.google.com/apis/gdata/docs/auth/oauth.html#UseAccessToken

The examples on the Google site for Java, PHP and Python all show
usage like this:

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
oauthParameters.setOAuthToken(ACCESS_TOKEN);
oauthParameters.setOAuthTokenSecret(TOKEN_SECRET);

DocsService client = new DocsService("yourCompany-YourAppName-v1");
client.setOAuthCredentials(oauthParameters, new
OAuthHmacSha1Signer());



The problem is .setOAuthCredentials method of the client library
DOESN'T EXIST in the .Net library.


Please - how do I authenticate my service with the Oauth tokens I
have? 6+ hours and counting of banging my head on the desk - I'm
bleeding here folks :-)

Shane


Claudio Cherubino

unread,
Nov 24, 2010, 6:44:36 AM11/24/10
to gdata-dotnet-...@googlegroups.com
Hi Shane,

We are working to update our documentation to include a .NET 3LO sample, in the meanwhile please use this Spreadsheet API code as reference:


GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("wise", APPLICATION_NAME);
requestFactory.ConsumerKey = "anonymous";
requestFactory.ConsumerSecret = "anonymous";
requestFactory.Token = TOKEN_KEY;
requestFactory.TokenSecret = TOKEN_SECRET;
requestFactory.UseSSL = true;

SpreadsheetsService myService = new SpreadsheetsService(APPLICATION_NAME);
myService.RequestFactory = requestFactory;

SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = myService.Query(query);
...


Claudio




--
You received this message because you are subscribed to the Google Groups "Google Data APIs .NET Client Library" group.
To post to this group, send email to gdata-dotnet-...@googlegroups.com.
To unsubscribe from this group, send email to gdata-dotnet-client...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gdata-dotnet-client-library?hl=en.


Shane

unread,
Nov 24, 2010, 10:24:20 PM11/24/10
to Google Data APIs .NET Client Library
Claudio,


Thanks so much. I had some code that used GOAuthRequestFactory but I
didn't have the SSL set and I had the wrong application name. It
failed each time.

With your help I now have 3 Legged OAuth working great with Google
Contacts API. Awesome stuff - thanks for the support!

Shane
> > gdata-dotnet-client...@googlegroups.com<gdata-dotnet-clien t-library%2Bunsu...@googlegroups.com>
> > .

Cory

unread,
Dec 13, 2010, 4:55:27 PM12/13/10
to Google Data APIs .NET Client Library
Hey Claudio,
I'm experiencing the same problem as Shane. I have my consumer key,
consumer secret, access token, and access secret. After trying the
above code (but using with contact/calendar services) I'm experiencing
no luck.
Is the APPLICATION_NAME something that needs to be registered with
Google also (our consumer key and secret are registered)? Here is a
copy of my code....

GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl",
"theAppName");
requestFactory.ConsumerKey = "myConsumerKey";
requestFactory.ConsumerSecret = "myConsumerSecret";
requestFactory.Token = "token";
requestFactory.TokenSecret = "secret";
requestFactory.UseSSL = true;

CalendarQuery query = new CalendarQuery();
Uri calendarUri = new Uri("http://www.google.com/
calendar/feeds/default/allcalendars/full");
query.Uri = calendarUri;

CalendarService service = new
CalendarService("theAppName");
service.RequestFactory = requestFactory;
service.Query(query);
Console.WriteLine("Query Success!");


Any help with be greatly appreciated!

Thanks,
Cory

On Nov 24, 10:24 pm, Shane <shanemenchi...@gmail.com> wrote:
> Claudio,
>
> Thanks so much.  I had some code that used GOAuthRequestFactory but I
> didn't have the SSL set and I had the wrong application name.  It
> failed each time.
>
> With your help I now have3LeggedOAuthworking great with Google
> Contacts API.  Awesome stuff - thanks for the support!
>
> Shane
>
> > > Please - how do I authenticate my service with theOauthtokens I

Claudio Cherubino

unread,
Dec 14, 2010, 4:46:16 AM12/14/10
to gdata-dotnet-...@googlegroups.com
Hi Cory,

The value of APPLICATION_NAME doesn't need to be registered, it will only be used for logging purposes.
Since you are using 3-legged OAuth, you should leave ConsumerKey and ConsumerSecret as "anonymous" (check the sample I sent) and only set Token and TokenSecret.
I haven't tried your code yet, but I'm confident that will fix it.

Claudio

To unsubscribe from this group, send email to gdata-dotnet-client...@googlegroups.com.

Shane

unread,
Dec 14, 2010, 12:16:37 PM12/14/10
to Google Data APIs .NET Client Library
Heh Cory,

Below is my code that I am using fine with the Google Contacts API.
Seems strange but I am in fact setting the consumer key and consumer
secret and it works fine for me.

Are you sure the Token and Token Secret you are getting back in the
OAuth valid and you are not getting an unauthorized error when you are
creating and then using the Requestfactory?

Shane




//setup a request factory with the Google .Net Library to auth the
requestor with OAuth
GOAuthRequestFactory requestFactory = new
GOAuthRequestFactory("cp", AuthCred.ConsumerKey);
requestFactory.ConsumerKey = AuthCred.ConsumerKey;
requestFactory.ConsumerSecret = AuthCred.ConsumerSecret;
requestFactory.Token = AuthCred.AccessToken;
requestFactory.TokenSecret = AuthCred.AccessSecret;
requestFactory.UseSSL = true;
GContactService = new ContactsService("Contact
Infomation");
GContactService.RequestFactory = requestFactory;

ContactsQuery query = new
ContactsQuery(ContactsQuery.CreateContactsUri("default"));
query.StartIndex = 0;
query.NumberToRetrieve = 500;
ContactsFeed feed;
try
{
feed = GContactService.Query(query);
}
catch (GDataRequestException error)
{
throw new System.ApplicationException("Not Authorized
to access Google data. Please Auth this user.", error);
}
foreach (ContactEntry entry in feed.Entries)
{
.........
> > > > > gdata-dotnet-client...@googlegroups.com<gdata-dotnet-clien t-library%2Bunsu...@googlegroups.com><gdata-dotnet-clien
> > t-library%2Bunsu...@googlegroups.com<t-library%252Bunsubscribe@googlegr oups.com>

Cory

unread,
Dec 14, 2010, 2:08:43 PM12/14/10
to Google Data APIs .NET Client Library
Dear Claudio and Shane,
Thank you for your quick responses. I finally got it working!!

Cory
> > >http://groups.google.com/group/gdata-dotnet-client-library?hl=en.- Hide quoted text -
>
> - Show quoted text -

symbiotics

unread,
Dec 22, 2010, 7:18:33 AM12/22/10
to Google Data APIs .NET Client Library
Hi Folks,

Thanks for sharing the code that you get to work, I can't even get the
tokens yet.

I've got OAuth working already for Delicious, they are using OAuth
v2.0. It seems much harder to get it working with Google's API's! Do
the Google API's use OAuth v2.0 or v1.0?

If someone has a chance to share any code about how to obtain the
Tokens I'd be obliged!

Thanks

Austin
> > > > > > > To unsubscribe from this group, send email to> > > > > >gdata-dotnet-client...@googlegroups.com<gdata-dotnet-client-library%2Bunsu...@googlegroups.com><gdata-dotnet-clien> > >t-library%2Bunsu...@googlegroups.com<t-library%252Bunsubscribe@googlegr oups.com>
>
> > > > > > > .
> > > > > > > For more options, visit this group at
> > > > > > >http://groups.google.com/group/gdata-dotnet-client-library?hl=en.
>
> > > > --
> > > > You received this message because you are subscribed to the Google Groups
> > > > "Google Data APIs .NET Client Library" group.
> > > > To post to this group, send email to> > >gdata-dotnet-...@googlegroups.com.
> > > > To unsubscribe from this group, send email to> > >gdata-dotnet-client...@googlegroups.com<gdata-dotnet-client-library%2Bunsu...@googlegroups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/gdata-dotnet-client-library?hl=en.-Hide quoted text -
Reply all
Reply to author
Forward
0 new messages