简体   繁体   English

获取我和我的朋友的帖子(Wall Facebook)

[英]Get Posts (Wall Facebook) of me and my friends

I use https://developers.facebook.com/tools/access_token/ 我使用https://developers.facebook.com/tools/access_token/

I create an App. 我创建一个应用程序。 I want get Posts of the wall of me and my friends. 我想获得我和我朋友的墙的帖子。

I try me/feed and me/posts but I get nothing. 我尝试me/feedme/posts但我什么也没得到。

I have this unit test. 我有这个单元测试。

Any suggestions? 有什么建议么?

    [TestMethod]
    public void Basic_using_SDK()
    {
        // http://blog.prabir.me/posts/facebook-csharp-sdk-making-requests
        var fb = new Facebook.FacebookClient();

        var result = (IDictionary<string, object>)fb.Get("4");

        var id = (string)result["id"];
        var name = (string)result["name"];
        var firstName = (string)result["first_name"];
        var lastName = (string)result["last_name"];
        var link = (string)result["link"];
        var username = (string)result["username"];
        var gender = (string)result["gender"];
        var male = (string)result["locale"];


        var parameters = new Dictionary<string, object>();
        parameters["fields"] = "id,name";

        result = (IDictionary<string, object>)fb.Get("4", parameters);
        id = (string)result["id"];
        name = (string)result["name"];


        dynamic result2 = fb.Get("4");

        id = result2.id;
        name = result2.name;
        firstName = result2.first_name;
        lastName = result2.last_name;
        link = result2.link;
        username = result2.username;
        gender = result2.gender;
        male = result2.locale;


        dynamic parameters2 = new ExpandoObject();
        parameters2.fields = "id,name";

        dynamic result3 = fb.Get("4", parameters);
        id = result3.id;
        name = result3.name;

        dynamic me = fb.Get("zuck");
        firstName = me.first_name;
        lastName = me.last_name;


        var client = new FacebookClient(AccessToken);
        dynamic me2 = client.Get("me");
        string aboutMe = me2.about;

        dynamic result4 = client.Get("/me/feed");

        foreach (dynamic post in result4.data)
        {
            var fromName = post.from.name;
            Console.WriteLine(fromName);
        }

        dynamic result5 = client.Get("/me/posts");
        for (int i = 0; i < result5.Count; i++)
        {
        }


        // https://www.facebook.com/profile.php?id=xxxxxxx
        // https://graph.facebook.com/xxxxxxx
        var uidKiquenet = "xxxxx";
        var query = string.Format(@"SELECT status_id,message,time,source,uid,place_id
                            FROM status WHERE uid IN (SELECT uid FROM status WHERE uid = '" + uidKiquenet + "') ORDER BY time DESC");

        dynamic parameters6 = new ExpandoObject();
        parameters6.q = query;

        dynamic results6 = fb.Get("/xxxxx?fields=id,name,age_range,about,email,first_name,gender");


        string myMessage = "Hello from Test";

        fb.PostTaskAsync("me/feed", new { message = myMessage }).ContinueWith(t =>
        {
            if (!t.IsFaulted)
            {
                string message = "Great, your message has been posted to you wall!";
                Console.WriteLine(message);
            }
        });

        fb.GetTaskAsync("me").ContinueWith(t =>
        {
            if (!t.IsFaulted)
            {
                var result11 = (IDictionary<string, object>)t.Result;
                string myDetails = string.Format("Your name is: {0} {1} and your Facebook profile Url is: {3}",
                                                  (string)result11["first_name"], (string)result11["last_name"],
                                                  (string)result11["link"]);
                Console.WriteLine(myDetails);
            }
        });

        // This uses Facebook Query Language
        // See https://developers.facebook.com/docs/technical-guides/fql/ for more information.
        query = string.Format("SELECT uid,name,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) ORDER BY name ASC", "me()");

        fb.GetTaskAsync("fql", new { q = query }).ContinueWith(t =>
        {
            if (!t.IsFaulted)
            {
                var result1 = (IDictionary<string, object>)t.Result;
                var data = (IList<object>)result1["data"];
                var count = data.Count;
                var message = string.Format("You have {0} friends", count);
                Console.WriteLine(message);

                foreach (IDictionary<string, object> friend in data)
                    Console.WriteLine((string)friend["name"]);
            }
        });

    }

You must authorize with the correct permission in order to get access to feed posts. 您必须获得正确的许可授权才能访问摘要帖子。 Try authorizing with user_posts , as it is explained in the docs: https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed#read 尝试使用user_posts授权,如docs中所述: https : //developers.facebook.com/docs/graph-api/reference/v2.3/user/feed#read

Be aware that this does not get you access to posts of friends, unless they posted on the wall of the authorized user. 请注意,除非他们发布在授权用户的墙上,否则您无法访问他们的帖子。

About review, you may want to read this: https://developers.facebook.com/docs/facebook-login/review/faqs#what_is_review 关于评论,您可能需要阅读以下内容: https : //developers.facebook.com/docs/facebook-login/review/faqs#what_is_review

Btw, FQL is deprecated and will only work in v2.0 Apps - not in newer ones. 顺便说一句,FQL已过时,仅在v2.0 Apps中可用-不适用于较新的版本。

Same thing happened to me . 同样的事情发生在我身上 。 Here is my Solution 这是我的解决方案

I made my project registered on Facebook developer console. 我在Facebook开发者控制台上注册了我的项目。 Then I did my code same as you but could not get posts / information . 然后,我和您一样执行了我的代码,但是无法获取帖子/信息。 After some time i submitted my application for app review to facebook team (it was still in early development phase) and after their feedback I got my code working . 一段时间后,我将我的应用程序提交给了Facebook团队以进行应用程序审查(它仍处于早期开发阶段),在他们的反馈之后,我的代码开始工作了。 So pending Application review can be your issue also . 因此,待审核的应用程序也可能是您的问题。 This option is available in application setting . 该选项在应用程序设置中可用。 Give it a shot 试一试

Update Another code sample is here 更新另一个代码示例在这里

 if (Request["code"] == null)
            {
                Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                    FB_app_id, Request.Url.AbsoluteUri, FB_scope));
                return false;
            }
            else
            {
                Dictionary<string, string> tokens = new Dictionary<string, string>();
                string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}&perms=status_update"
                    , FB_app_id, Request.Url.AbsoluteUri, FB_scope, Request["code"].ToString(), FB_secret_id);
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {

                    StreamReader rd = new StreamReader(response.GetResponseStream());

                    string vals = rd.ReadToEnd();
                    foreach (string token in vals.Split('&'))
                    {
                        tokens.Add(token.Substring(0, token.IndexOf('=')), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf('=') - 1));
                    }
                    string access_token = tokens["access_token"];
                    Session["fb_access_token"] = access_token;

                    return true;


                }

            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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