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

问题描述 投票:4回答:6

我正在尝试使用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
  }
}

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

谢谢

php facebook facebook-graph-api notifications
6个回答
5
投票
  • 尽快更改您的应用程序密码,您不应在这些问题中包含私人信息
  • 然后,检查应用程序的高级设置,并将应用程序类型设置为“Web”,而不是“本机/桌面” - 如果设置为本机/桌面,则应用程序机密不受信任且需要应用程序访问令牌的调用将失败。

3
投票

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

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

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


0
投票

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

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

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

编辑:我整晚和第二天早上一直在争论这个问题,我最终决定放弃它。这个API肯定存在我无法理解的问题,我无法在任何地方找到任何解决方案。

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

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

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

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;
};

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


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功能。


0
投票

尝试更改Graph Explorer顶部字段中的Access Token,不要将其添加到URL。

Access Token: xxxxxx|YYYYYY

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

0
投票

转到你的设置=> Basic => App Secret,然后使用该密钥作为密钥

© www.soinside.com 2019 - 2024. All rights reserved.