![](/img/trans.png)
[英]How to solve 'This method must be called with an app access_token' error?
[英]Facebook notifications API: “This method must be called with an app access_token”
我正在嘗試使用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
}
}
我會說它在一個月前工作了......有什么想法嗎?
謝謝
我也試圖使用圖形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;
};
這真讓我瘋了......
因此,因為我使用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功能。
嘗試更改Graph Explorer頂部字段中的Access Token,不要將其添加到URL。
Access Token: xxxxxx|YYYYYY
POST: /11093774316/notifications?template=Hello&href=index.php
轉到你的設置=> Basic => App Secret,然后使用該密鑰作為密鑰
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.