Facebook通知API:“必须使用app access_token调用此方法”

时间:2012-10-07 17:23:48

标签: php facebook facebook-graph-api notifications

我正在尝试使用Graph API Explorer从我的应用发送Facebook通知。所以我选择了我的应用程序POST,并在/

之后输入了这个字符串
11093774316/notifications?access_token=430xxxxxx156|HU0ygMtxxxxxxxxxxxxikVKg&template=Hello&href=index.php

访问字符串是我在“访问令牌调试器”上获得的,我检查它是否正常。

但是,我收到此错误消息:

{
  "error": {
    "message": "(#15) This method must be called with an app access_token.", 
    "type": "OAuthException", 
    "code": 15
  }
}

我会说它在一个月前工作了......有什么想法吗?

由于

6 个答案:

答案 0 :(得分:5)

  • 尽快更改您的应用程序密码,您不应在这些问题中包含私人信息
  • 然后,检查应用的高级设置,并将应用类型设置为“网络”,而不是“原生/桌面”设置。 - 如果将其设置为本机/桌面,则应用密钥不受信任,并且需要应用访问令牌的呼叫将失败。

答案 1 :(得分:3)

尝试使用此处的访问令牌:

https://developers.facebook.com/tools/access_token/

我遇到了同样的问题,我已经解决了这个问题。

答案 2 :(得分:0)

我也试图使用图形api发布通知。 我首先请求app access_token,它已正确返回。 然后我将它用作通知请求的参数,就像应该这样做。 但是,我仍然收到同样的错误消息“必须使用app access_token调用此方法”... 是的,该应用程序配置为Web应用程序。

前五个小时这很有趣,但它有点烦人......

任何其他想法,世界?请?

修改我整晚都在讨论这个问题,第二天早上,我最终决定放弃它。这个API肯定存在我无法理解的问题,而且我无法在任何地方找到任何解决方案。

关于我做什么的一些细节,以防有人想出一个想法:

这是一个使用Facebook iOS SDK的iOS应用程序。 登录,授权,获取朋友资料,在我的墙上发布消息:一切正常。

然后,为了发送通知,我首先发送请求以检索应用访问令牌。

NSDictionary* parameters = @{@"client_id": [THE APP FACEBOOK ID], @"client_secret" : [THE APP FACEBOOK SECRET], @"grant_type" : @"client_credentials"};

NSURL* feedURL = [NSURL URLWithString:@"https://graph.facebook.com/oauth/access_token"];

SLRequest *feedRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:feedURL parameters:parameters];
feedRequest.account = self.account;
[feedRequest performRequestWithHandler ... ]

请求回答:

NSString* tokenString = [[NSString alloc]  initWithBytes:[responseData bytes] length:[responseData length] encoding: NSUTF8StringEncoding];
NSArray* chunks = [tokenString componentsSeparatedByString: @"="];
NSString* appAccessToken = [chunks objectAtIndex:1];

NSLog(@"appAccessToken '%@'", appAccessToken);

这似乎按预期工作。我明白了:

appAccessToken '1309[HIDDEN]|-eta-nuWz[HIDDEN]'

现在,我尝试发布通知

NSDictionary* parameters = @{@"href": [myHref absoluteString], @"access_token" : appAccessToken, @"template" : myMessage};
NSURL* feedURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/notifications", theRecipientFacebookId];
SLRequest* feedRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:parameters];
    feedRequest.account = self.account;
    [feedRequest performRequestWithHandler: ... ]

不幸的是,我一直这样:

error =     {
    code = 15;
    message = "(#15) This method must be called with an app access_token.";
    type = OAuthException;
};

这真让我疯了......

答案 3 :(得分:0)

所以,因为我使用Graph Api Explorer取得了成功,所以我有理由绕过SLRequest对象,转而采用通常的post请求(使用AFNetworking)。

NSURL* url = [NSURL URLWithString:@"https://graph.facebook.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: appToken, @"access_token", @"index.php", @"href", @"hello", @"template", nil];

[httpClient postPath:[NSString stringWithFormat:@"/%@/notifications", theRecipientFacebookId] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
            NSLog(@"Request Successful, response '%@'", responseStr);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"[HTTPClient Error]: %@", error.localizedDescription);
        }];

我获得成功:真实! 因此,如果我不得不猜测,我建议使用SLRequest时覆盖access_token参数(应用程序访问令牌),并被其他“access_token”(用户访问令牌)覆盖。 如果这是实际的解释,那当然是有道理的。但为什么那些令牌应该有相同的名字呢?

编辑:我确实看到了通知,现在,它有效。所以问题肯定来自于使用SLRequest,我认为它会覆盖access_token参数。

附加信息:您无法向尚未安装该应用程序的用户发送通知。为了“邀请朋友”,现在似乎唯一的解决方案是使用facebook SDK中的Dialog功能。

答案 4 :(得分:0)

尝试更改图表资源管理器顶部字段中的访问令牌,不要将其添加到URL。

Access Token: xxxxxx|YYYYYY

POST: /11093774316/notifications?template=Hello&href=index.php

答案 5 :(得分:0)

转到您的设置=>基本=> App Secret并将密钥用于密钥然后我们