1

I have developed an application to download user names and Ids from face book graph API. But I cannot get their public information like birthdays.

So my approach is to download HTML of about pages and read Birthday from that. my code follows; I developed my application in MVC4:

public ActionResult ExternalLoginCallback(string returnUrl)
    {
        AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
        if (!result.IsSuccessful)
        {
            return RedirectToAction("ExternalLoginFailure");
        }

        if (result.ExtraData.Keys.Contains("accesstoken"))
        {
            Session["facebooktoken1"] = result.ExtraData["accesstoken"];

            string fbToken = result.ExtraData["accesstoken"];

            ViewBag.TokenToview = fbToken;

            ViewBag.Id = 5;

            WebRequest myWebRequest = WebRequest.Create("https://www.facebook.com/amila.u.abeyrathne/about");
            WebResponse myWebResponse = myWebRequest.GetResponse();
            Stream ReceiveStream = myWebResponse.GetResponseStream();
            Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
            StreamReader readStream = new StreamReader(ReceiveStream, encode);
            string strResponse = readStream.ReadToEnd();

        }

When I use this I only get html of LOG IN page of facebook. How can I use my facebook login session in this application?

OnoSendai
  • 3,960
  • 2
  • 22
  • 46

4 Answers4

1

To get information like this, you'd need to hit Facebook Graph API endpoints like mentioned here . You'd need an access token gneerated with the necessary permissions as specified here in order to submit a working request. I'm assuming the access token you're using in this code is generated by querying OAuth in the specified manner.

ramdesh
  • 650
  • 6
  • 22
  • I have to deal with anonymous users. Not only with friends. any of FB api's not letting to do that. That is why I am trying to download HTML from about pages of each user.I tried this. – Amila Upeksha Abeyrathne Nov 15 '13 at 18:15
  • Can't you return public details like that through a GET request to a Graph API endpoint? For example, just pointing your browser to http://graph.facebook.com/rdeshapriya?fields=id,name,picture will give a set of details about me. – ramdesh Nov 15 '13 at 19:12
  • @ramdesh- i have already downloaded data you mentioned. But additional data like birthday, education is not provided by graph or any other API. That is why I am trying to download html content – Amila Upeksha Abeyrathne Nov 16 '13 at 02:59
1

It is not possible to get those information from facebook graph Search.The solution is to develop application that can log in to facebook and scrap the HTML of the facebook wall of each user whom userids have being downloaded. After scraping the HTML read the text from htlm is the solution. But it is not that much accurate. Birthdays and other information in the about page is not possible to read on that way either because there is no way to navigate to the about page in that way.

0

Ur application session data cannot be read by facebook API, so need to send the token in subsequent requests.

Getting FB Page data from facebook using C#

Community
  • 1
  • 1
madufit1
  • 206
  • 3
  • 10
0

I think your approach is wrong. when you log in to a website it is created session cookie in client browser. Then it append to each request header when send request to that web site again. session cookie created on client browser not the server.

What you are doing is you send request to facebook from your server not from the client. Then there is no valid session cookie append to your request.

If you what to go this way you have to read the facebook page using javascript. But it is not the recommended way.

You need to crate facebook app for your website.

Then need to Select permissions to request from users. (for your case use user_birthday )

Then authenticate your website using that app. Then you can get what ever the details that you want using graph api if users gave permission.

Milina Udara
  • 597
  • 1
  • 9
  • 24