Friday, December 24, 2010

Facebook OAuth - more information

Recently, I had to incorporate OAuth for Facebook.

I ran into a few issues.

First and foremost, I had a "Invalid redirect_uri: Given URL is not allowed by the Application configuration" error.

After some trolling on the net, I found that this can be corrected by Url-encoding the redirect_uri parameter.

Using C#, you can fix this by simply, using the Server.UrlEncode function.



Then, I hit a "Error validating verification code." error.

This is fixed by using a Http-GET rather than a Http-POST to retrieve the information.

To do this, simply do the following.
1. Instantiate a URI object and passing the https://graph.facebook.com/oauth/access_token with relevant parameters. See here for more info.
2. Create a HttpWebRequest object.
3. Setting the http web request "method" attribute to GET.
4. Create a HttpWebResponse object.
5. Create a stream reader object and this should return you the access_token values.



To log-in without a user, simply add "&type=client_cred" to 1.

No comments:

Post a Comment