简体   繁体   中英

.net desktop facebook sdk UserToken

I am trying to write a simple Facebook Desktop app (C# WPF). The only thing the program should display, is a users timeline. I am quite new to the .net Facebook sdk (v 6.0). I have read a lot of documentation on the sdk site and also at the Facebook developer site. So far everything sounds clear except one thing. I have big problems with the whole login thing. As i read on the developer site i need to get an user access token to get a user's "private" data. As described on the sdk site the only way to get such a token is to open the browser with the right URI and retrive the token from it. Is this really the only way to do this? I do not want to open a browser or something like that. Is there no way to send the username and password to some kind of webservice or whatever to get the token? Does anyone have an idea how i can get the token without a browser?

Kind Regards Manuel

No need to open a browser. Just embeed a WebBrowser control inside your form and put it non-visible.

Add a handler to Navigated event:

 webBrowser1.Navigated += new WebBrowserNavigatedEventHandler(webBrowser1_Navigated);

And get the answer from the server:

This code is done one year ago , I dont know if they have changed the API but It was working perfect.

void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
            string Url = e.Url.AbsoluteUri.ToString();
            if (Url.StartsWith("https://www.facebook.com/connect/login_success.html"))
            {
                if (Url.Contains("#") && Url.Contains("access_token="))
                {
                 AccessToken = Url.Substring(Url.IndexOf("access_token=") + 13 , Url.Length - Url.IndexOf("access_token") -13);
                    if (AccessToken.Contains("&"))
                    {
                    AccessToken = AccessToken.Substring(0, AccessToken.LastIndexOf("&"));   
                    }    
                } 
            }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM