开发者

Facebook API : Data dump of Comment/Like Data

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/开发者_如何学JAVAoauth/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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜