我有一个执行查询的命令行应用程序。这是代码。
问题是它收到“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 ;
有什么想法吗?
答案 0 :(得分:1)
您获得的错误来自Facebook,它只是说您没有有效的令牌来发出请求。您必须使用OAuth请求用户访问令牌。拥有有效的访问令牌后,您可以使用以下代码发出请求:
var fb = new FacebookClient("valid_user_access_token");
string query = "YOUR FQL QUERY HERE";
dynamic result = fb.Query(query);
要了解如何获取有效的访问令牌,请阅读此处的Facebook文档:https://developers.facebook.com/docs/authentication/