0

[ My humble request: please don't ignore this question just by adding some reference question link. I read all the reference i can, but i didnt get what i need]

I am trying to make a windows/console application where i need to access the user details offline. So i tried the following code.

String finalRedirectUri = "https://www.facebook.com/dialog/oauth?client_id=" + 
    _appKey2 + "&redirect_uri=" + _SiteURL + "&scope=email,read_stream";
String GraphUri = "https://graph.facebook.com/oauth/access_token?client_id=" + 
    _appKey2 + "&redirect_uri=" + _SiteURL + "&scope=email,read_stream";

FacebookClient client = new FacebookClient(_appKey2, _secret2);
FacebookOAuthClient oAuthClient = 
    new FacebookOAuthClient(FacebookApplication.Current);
oAuthClient.AppId = _appKey2;
oAuthClient.AppSecret = _secret2;
oAuthClient.RedirectUri = new Uri(finalRedirectUri);
String Uri = oAuthClient.GetLoginUrl().ToString();

try
{
    dynamic tokenResult = 
        oAuthClient.ExchangeCodeForAccessToken("offline_access");
}
catch (Exception exp)
{
    MessageBox.Show("" + exp.Message);
}

I am always getting error message: " (OAuthException) Invalid verification code format" I searched many links in stackoverflow and http://developers.facebook.com/docs/authentication/ also but it didnt helped me to find the solution. I dont even know which uri to use. I am using Visual Studio 2010 [ Please donot simply ignore this question just by marking as duplicate] Be gentle to me please..

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
new_programmer
  • 840
  • 3
  • 12
  • 22

1 Answers1

0

It's possible that if you downloaded the compiled facebook dll (from NuGet for example), that it's badly built. Try downloading the source and compiling it yourself and using that dll. Here is an example of a post with the same problem.
note even though their problem is giving a different error, it's possible this is precisely the problem you have, as it's in the same function your variant may just be running into another one of their mistakes.

here are two other possible problems you may be having:
Sometimes, redirect uri should be null
OAuth really likes the '/' at the end of a uri

Community
  • 1
  • 1
  • @Shingestu, _appKey2 and _secret2 are correct format only because when i ran the appln in debug mode i got a value in finalRedirectUri which when i copied to the browser addressbar, it redirected to the screen for application approval. Thank you Shingestu, I hope my point is clear. – new_programmer Mar 04 '12 at 15:16
  • Can it be that FacebookApplication.Current is not a valid constructr argument for oAuthClient? –  Mar 04 '12 at 15:31
  • What line does the error appear on? Run it through a debugger plz. –  Mar 04 '12 at 16:28
  • i am getting error from the code which is written in try. I tried to run with "code" instead of "offline_access" – new_programmer Mar 05 '12 at 07:01
  • Where did you get the facebook dll? –  Mar 05 '12 at 21:19
  • i dont have any idea abt the site from where i got the facebook.dll, if you have any suggestion for a dll so that i could use it for getting offline_access for window/console C# application it would be really great. [i searched many site ] – new_programmer Mar 08 '12 at 07:34