httpwebrequest facebook登录和请求应用令牌

本文关键字:应用 令牌 请求 facebook 登录 httpwebrequest | 更新日期: 2023-09-27 18:09:00

我试图登录facebook并通过使用此链接检索令牌:https://www.facebook.com/dialog/oauth?client_id=282892925078054& redirect_uri = https://www.facebook.com/& response_type =标记

我的代码看起来像这样,但我得到一个无效的链接,当我请求上面的链接。

         CookieCollection cookies = new CookieCollection();
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.facebook.com/login.php?login_attempt=1"); 
         request.CookieContainer = new CookieContainer();
         request.CookieContainer.Add(cookies);
         //Get the response from the server and save the cookies from the first request..
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         cookies = response.Cookies;

         string getUrl = "https://www.facebook.com/login.php?login_attempt=1";
         string postData = String.Format("email={0}&pass={1}", email, pass);
         HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
         getRequest.CookieContainer = new CookieContainer();
         getRequest.CookieContainer.Add(cookies); //recover cookies First request
         getRequest.Method = WebRequestMethods.Http.Post;
         getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
         getRequest.AllowWriteStreamBuffering = true;
         getRequest.ProtocolVersion = HttpVersion.Version11;
         getRequest.AllowAutoRedirect = true;
         getRequest.ContentType = "application/x-www-form-urlencoded";
         byte[] byteArray = Encoding.ASCII.GetBytes(postData);
         getRequest.ContentLength = byteArray.Length;   
         Stream newStream = getRequest.GetRequestStream(); //open connection
         newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
         newStream.Close();
         HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
         cookies = getResponse.Cookies;
         using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
         {
           string sourceCode = sr.ReadToEnd();
         }
         //Get the token
         HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://www.facebook.com/dialog/oauth?client_id=282892925078054&redirect_uri=https://www.facebook.com/&response_type=token");
         getRequest.CookieContainer = new CookieContainer();
         getRequest.CookieContainer.Add(cookies);
         webRequest.AllowAutoRedirect = false;
         HttpWebResponse rresponse = (HttpWebResponse)webRequest.GetResponse();
         if (rresponse.StatusCode == HttpStatusCode.Redirect)
         {
             Console.WriteLine("redirected to: " + rresponse.GetResponseHeader("Location"));
         }

请帮帮我。

httpwebrequest facebook登录和请求应用令牌

https://www.facebook.com/dialog/oauth?client_id=282892925078054&redirect_uri=https://www.facebook.com/&response_type=token

URL不允许应用程序配置。:应用程序设置不允许使用一个或多个url。Internet Site URL和Canvas URL或域URL必须是应用程序域的子域