开发者

Facebook FQL page_user

开发者 https://www.devze.com 2023-04-06 22:38 出处:网络
Right i have a problem which i have done so much research for that i still cant be able to solve the problem. What i am trying to achieve is when a facebook user LIKES my page not an app, i want to be

Right i have a problem which i have done so much research for that i still cant be able to solve the problem. What i am trying to achieve is when a facebook user LIKES my page not an app, i want to be able to retrieve all the users that have liked the facebook page.

I am using FQL but having no luck at all, if i do an FQL based on the admins of the page it brings the data up.

SELECT first_name, last_name FROM user WHERE uid IN (SELECT uid FROM page_fan WHERE page_id = [your page id]) 

the above FQL should work. But nothing is being displayed, is this a facebook bug that has not been flagged or fixed?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCFacebookTestApp.Models;
using Facebook;
using Facebook.Web;


namespace MVCFacebookTestApp.Controllers
{
public class HomeController : Controller
{

    public FacebookSession FacebookSession
    {
        get { return (FacebookWebContext.Current.Session); }
    }
    public ActionResult Index()
    {
        string request = Request.Form["signed_request"];

        string accessToken = "";

        if (Request.Form["access_token"] != null)
        {
            accessToken = Request.Form["access_token"];
        }

        FacebookApplication app = new FacebookApplication();

        FacebookSignedRequest result = FacebookSignedRequest.Parse(app.InnerCurrent, request);

        if (String.IsNullOrWhiteSpace(accessToken))
        {
            accessToken = result.AccessToken;
        }

        dynamic data = result.Data;

        bool liked = data.page.liked;
        //bool liked = true;

        if (!liked)
        {
            Home h = Home.NotLiked();
            return View(h);
      开发者_开发问答  }
        else
        {
            Home h = Home.Liked();

            FacebookWebClient fb = null;

            if (String.IsNullOrWhiteSpace(accessToken))
            {
                var fbRequest = FacebookWebContext.Current;
                if (fbRequest.IsAuthorized())
                    fb = new FacebookWebClient(fbRequest);
            }
            else
            {
                fb = new FacebookWebClient(accessToken);
            }

            if (fb != null)
            {

                dynamic r = fb.Get("/me");

                h.TestString2 += " Ha! We captured this data about you!";

                h.TestString2 += " Name: " + r.name;

                h.TestString2 += " Location: " + r.location;

                h.TestString2 += " Birthday: " + r.birthday;

                h.TestString2 += " About Me: " + r.aboutme;

                h.ImgUrl = "http://graph.facebook.com/" + r.id + "/picture?type=large";



                string fqlResult = "";
                var fbApp = new FacebookClient(accessToken);

                //basic fql query execution
                dynamic friends = fbApp.Query("SELECT uid FROM page_admin WHERE page_id='160828267335555'");

                //SELECT uid FROM page_fan WHERE page_id = 160828267335555

                //"SELECT uid FROM page_fan WHERE uid=me() AND page_id=<your page id>";

                //loop through all friends and get their name and create response containing friends' name and profile picture
                foreach (dynamic friend in friends)
                {
                    fqlResult += friend.uid + "<br />";
                    //fqlResult += friend.name + "<img src='" + friend.pic_square + "' alt='" + friend.name + "' /><br />";
                }

                ViewBag.Likes = fqlResult;
            }
            else
            {
                //Display a message saying not authed....
            }


            return View(h);

        }
    }
}
}

is there a solution out there that actually works? Please do get back to me ASAP your help would be much appreciated, will save me from losing all my hair with the stress LOL

Thanks in advance.


You can make a GET request to /USER_ID/likes/PAGE_ID (replacing the caps part with the relevant IDs) to check if a particular user is a fan of your page. This is the replacement for the old 'pages.isFan' API method. There's no way to retrieve a list of users that like your page.

0

精彩评论

暂无评论...
验证码 换一张
取 消