我想要一个 Facebook 页面,但我收到了这个错误:
{"error":{"message":"(#200) 权限错误","type":"OAuthException","code":200}}
正如您在我的代码中看到的那样,权限似乎没问题。请注意,当我想要像 www.google.com 这样的简单 URL 时,它可以工作!
仅当我想喜欢 Facebook 页面时才收到此错误。
这是我的代码:
-(IBAction) buttonTestRecoFB
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_actions",@"publish_stream",
nil];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// session might now be open.
[self sessionStateChanged:session state:status error:error];
}];
}
// FACEBOOK
//
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state)
{
case FBSessionStateOpen:
{
NSLog(@"FBSessionStateOpen");
if (session.isOpen)
{
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
NSLog(@"firtname = %@" , my.first_name);
/////////////////////////////////////////////////
NSString *theWholeUrl = [NSString stringWithFormat:@"https://graph.facebook.com/313449204401/likes?access_token=%@", session.accessToken];
NSLog(@"TheWholeUrl: %@", theWholeUrl);
NSURL *facebookUrl = [NSURL URLWithString:theWholeUrl];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:facebookUrl];
[req setHTTPMethod:@"POST"];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[responseData bytes]];
NSLog(@"responseData: %@", content);
/////////////////////////////////////////////////
}];
}
}