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 /
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.
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.
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
Go to your setting => Basic => App Secret and use that key for secret key then us
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....