Facebook notifications API: “This method must be called with an app access_token”

前端 未结 6 445
情深已故
情深已故 2021-01-14 02:29

I am trying to send a Facebook notification from my app using Graph API Explorer. So I have selected my app, POST, and entered this string after the /



        
相关标签:
6条回答
  • 2021-01-14 02:50

    Try using the access token from here :

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

    I had the same problem, and I've solved like that.

    0 讨论(0)
  • 2021-01-14 02:52
    • Change your app secret ASAP, you shouldn't include private info in these questions
    • Then, check the advanced settings of your app and make app type is set to 'Web', not to 'native/desktop' - if it's set to native/desktop the app secret isn't trusted and calls which need an app access token will fail.
    0 讨论(0)
  • 2021-01-14 02:53

    So, because I get a success using the Graph Api Explorer, I had the idea to bypass the SLRequest object, and go for the usual post request (using 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);
            }];
    

    AND I GET A SUCCESS:TRUE! So If I have to take a guess, I would suggest that the access_token parameter (the app Access Token) is being overwritten when using an SLRequest, and that is being overwritten by the other "access_token" (the user access token). If this is the actual explanation, it does make sense of course. But why the hell those tokens should have the same name?

    EDIT : I do see the notifications, now, it works. So the problem surely came from the use of SLRequest, which I believe overwrite the access_token parameter.

    ADDITIONAL INFO : you can't send a notification to a user that has not installed the application yet. In order to "invite a friend", it seems the only solution for now is to use the Dialog function from the facebook SDK.

    0 讨论(0)
  • 2021-01-14 03:00

    Try changing the Access Token in the top field of the Graph Explorer, do not add it to the URL.

    Access Token: xxxxxx|YYYYYY
    
    POST: /11093774316/notifications?template=Hello&href=index.php
    
    0 讨论(0)
  • 2021-01-14 03:02

    Go to your setting => Basic => App Secret and use that key for secret key then us

    0 讨论(0)
  • 2021-01-14 03:04

    I'm also trying to post a notification, using the graph api. I first request the app access_token, which is properly returned. I use it then as a parameter of the notification request, like it should be done. But still, I get this same error message "This method must be called with an app access_token"... and Yes, the app is configured as a Web Application.

    That was fun for the first five hours, but it's getting a little bit annoying...

    any other idea, world? please?

    EDIT: I've been fighting with this issue for the whole night and the following morning, I eventually decide to give it up. There is definitely a problem I don't understand with this API, and I'm not able to find any solution anywhere.

    A few details about what I do, in case someone comes up with an idea :

    it's an iOS app, using the Facebook iOS SDK. Login, authorizing, getting friends profile, posting a message to my wall : everything is working properly.

    Then, in order to send a notification, I first send a request to retrieve the app access token.

    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 ... ]
    

    The request answers :

    NSString* tokenString = [[NSString alloc]  initWithBytes:[responseData bytes] length:[responseData length] encoding: NSUTF8StringEncoding];
    NSArray* chunks = [tokenString componentsSeparatedByString: @"="];
    NSString* appAccessToken = [chunks objectAtIndex:1];
    
    NSLog(@"appAccessToken '%@'", appAccessToken);
    

    That seems to work as expected. I get :

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

    Now, I try to post the notification

    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: ... ]
    

    Unfortunately, I keep getting this :

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

    It's really driving me nuts....

    0 讨论(0)
提交回复
热议问题