1

我有一个执行查询的命令行应用程序。这是代码。

问题是它接收到“abc...|xyz...”形式的访问令牌。没有会话部分。但是返回的令牌对于执行我的查询以选择我的页面的见解是无用的。帮助 !!

       const string permissions  = "manage_pages,read_insights,offline_access";

        dynamic oauthClient = new FacebookOAuthClient() ;
        oauthClient.AppId = username ;
        oauthClient.AppSecret = password ;

        dynamic parameters = new ExpandoObject() ;
        parameters.scope = permissions ;
        parameters.response_type = "token" ;
        // parameters.grant_type = "client_credentials" ;

        dynamic result = oauthClient.GetApplicationAccessToken(parameters);
        string token =  result.access_token ;  
       // token comes back as "abc...|xyz..." 

        var fb = new FacebookClient(token); 
        string query = " select metric, value  " + 
                       " from insights  " + 
                       " where object_id = MY_PAGE and " + 
                       "       metric in ( 'page_impressions' , 'page_stories') and " + 
                       "       end_time >= end_time_date('2012-02-21') and " + 
                       "       end_time <= end_time_date('2012-02-11') and " + 
                       "       period = period('day') " ; 

        dynamic result2 = fb.Query(query) ;  // Exception generated on this line.

        return result2 ;

有任何想法吗?

4

1 回答 1

1

The error you are getting is from Facebook and it is simply saying you don't have a valid token to make the request. You must request a user access token using OAuth. After you have a valid access token you can make your request with the following code:

var fb = new FacebookClient("valid_user_access_token"); 
string query = "YOUR FQL QUERY HERE";
dynamic result = fb.Query(query);

To learn how to get a valid access token read the Facebook documentation here: https://developers.facebook.com/docs/authentication/

于 2012-02-24T04:00:03.193 回答