Facebook API:评论/点赞数据的数据转储

发布于 2024-10-26 20:49:05 字数 1096 浏览 4 评论 0原文

这是我的代码:

string code = Request.QueryString["code"];
string appId = "x";
string appSecret = "x";

if (code == "" || code == null)
{
    //request for authentication
    Response.Redirect("https://graph.facebook.com/oauth/authorize?client_id=" + appId + "&redirect_uri=http://localhost:62543/&scope=email,read_stream");
}
else
{
    var fb = new MyFB();
    fb.ApplicationSecret = appSecret;
    fb.ApplicationID = appId;
    string accessToken = fb.GetAccessToken(code);
    fb.AccessToken = accessToken;


    var fbc = new FacebookClient(accessToken);

    dynamic streams = fbc.Query("select post_id from stream where permalink  = 'http://www.facebook.com/kevin.clough/posts/882439437244'");
    Response.Write(streams.Count);

    dynamic results = fbc.Query("select comments, likes from Post where id = " + streams.post_id);

    foreach (dynamic comment in results.comments)
    {
        Response.Write(comment.from.name + ", " + comment.message  + "<br/>");
    }

} 

收到此错误“当使用与会话所有者不同的viewer_id查询流表时,无法使用会话。”

我如何授权此会话查看我自己的数据?

Here is my code:

string code = Request.QueryString["code"];
string appId = "x";
string appSecret = "x";

if (code == "" || code == null)
{
    //request for authentication
    Response.Redirect("https://graph.facebook.com/oauth/authorize?client_id=" + appId + "&redirect_uri=http://localhost:62543/&scope=email,read_stream");
}
else
{
    var fb = new MyFB();
    fb.ApplicationSecret = appSecret;
    fb.ApplicationID = appId;
    string accessToken = fb.GetAccessToken(code);
    fb.AccessToken = accessToken;


    var fbc = new FacebookClient(accessToken);

    dynamic streams = fbc.Query("select post_id from stream where permalink  = 'http://www.facebook.com/kevin.clough/posts/882439437244'");
    Response.Write(streams.Count);

    dynamic results = fbc.Query("select comments, likes from Post where id = " + streams.post_id);

    foreach (dynamic comment in results.comments)
    {
        Response.Write(comment.from.name + ", " + comment.message  + "<br/>");
    }

} 

Getting this error "A session cannot be used when querying the stream table with a viewer_id that is a different from the session owner."

How do I authorize this session to view my own data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人心善变 2024-11-02 20:49:05

所以我看到的第一个问题是查询无效。您有:

select post_id from stream 
where permalink  = 'http://www.facebook.com/kevin.clough/posts/882439437244'

根据 Facebook 文档此处,您只能使用以下命令查询流表:列 post_id、app_id、source_id、filter_key 和 xid。

因此,您应该将第一个查询更改为此(使用帖子 ID '19292868552_118464504835613' 作为示例):

select post_id from stream where post_id = '19292868552_118464504835613'

或者,您可以使用帖子 id 对图表执行相同的操作:

dyanmic post1 = fbc.Get("19292868552_118464504835613");

您的第二个查询是错误的,主要是因为您正在查询一个表不存在。

select comments, likes from Post where id = " + streams.post_id

没有这样的 FQL 表“Post”。我不确定这样做的目的是什么,但如果你想获得点赞和评论,我认为使用 Graph API 会更容易。

评论:

dynamic comments = fbc.Get("19292868552_118464504835613/comments");

喜欢:

dynamic likes = fbc.Get("19292868552_118464504835613/likes");

这是 Facebook 关于 Post Graph API 的文档:http://developers。 facebook.com/docs/reference/api/post/

编辑:

要确定用户的流项目,您需要阅读他们的提要。您也可以使用 Graph API 来完成此操作。

dynamic feed = fbc.Get("me/feed");
foreach (dynamic post in feed.data) {
    var post_id = post.id;
}

这将为您提供该用户的最新帖子。从那里您可以循环浏览它们以找到您想要获得更多详细信息的那个。

So the first problem I see is that the query is not valid. You have:

select post_id from stream 
where permalink  = 'http://www.facebook.com/kevin.clough/posts/882439437244'

Per the Facebook documentation here you can only query the stream table using the columns post_id, app_id, source_id, filter_key, and xid.

So you should change your first query to this (using post ID '19292868552_118464504835613' as an example):

select post_id from stream where post_id = '19292868552_118464504835613'

Alternatively, you could do the same thing with the graph using the post id:

dyanmic post1 = fbc.Get("19292868552_118464504835613");

Your second query is wrong mainly because you are querying a table that doesn't exist.

select comments, likes from Post where id = " + streams.post_id

There is no such FQL table 'Post'. I am not sure what the goal of this is, but if you want to get the likes and comments I think it would be easier to use the Graph API.

Comments:

dynamic comments = fbc.Get("19292868552_118464504835613/comments");

Likes:

dynamic likes = fbc.Get("19292868552_118464504835613/likes");

Here is Facebook's documentation on the Post Graph API: http://developers.facebook.com/docs/reference/api/post/

EDIT:

To determine the stream items of a user you will want to read their feed. You can do this using the Graph API also.

dynamic feed = fbc.Get("me/feed");
foreach (dynamic post in feed.data) {
    var post_id = post.id;
}

This will get you the most recent posts of the user. From there you can loop through them to find the one you want to get more details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文