使用社交框架工作Ios发布评分时出错

时间:2014-03-24 09:50:47

标签: ios iphone facebook facebook-graph-api facebook-ios-sdk

这是我发送新分数的方法:

-(void)sendScore :(int) score : (NSString *)uID : (ACAccount *)ac{
    NSString *url =[NSString stringWithFormat:@"https://graph.facebook.com/%@/scores",uID];
    NSURL * strURL =[NSURL URLWithString:url];
    NSDictionary * parameter =@{@"score": @"10000"};
    SLRequest * request =[SLRequest requestForServiceType:SLServiceTypeFacebook
                                            requestMethod:SLRequestMethodPOST URL:strURL parameters:parameter];
    request.account = _accFB;
    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        if (!error) {
            NSLog(@"Error: %@",error);
            NSString * str = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
            NSLog(@"str: %@",str);
        }

    }];
}

运行时,显示错误:

  

{   
“message”:“(#200)需要扩展权限:publish_actions”,   
“类型”: “OAuthException”   
“代码”:200   
}

如何添加publish_actions

1 个答案:

答案 0 :(得分:3)

您可以随时为活动会话请求其他权限。 Facebook 建议当您的应用实际需要他们完成用户发起的操作时,您会要求获得权限。另外注意,您无法一起添加读写权限。

以下是为活动会话请求publish_actions发布权限的代码 -

FB iOS SDK

[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                  defaultAudience:FBSessionDefaultAudienceFriends
                                completionHandler:^(FBSession *session, NSError *error) {
                                  __block NSString *alertText;
                                  __block NSString *alertTitle;
                                  if (!error) {
                                    if ([FBSession.activeSession.permissions 
                                         indexOfObject:@"publish_actions"] == NSNotFound){
                                      // Permission not granted, tell the user we will not publish
                                      alertTitle = @"Permission not granted";
                                      alertText = @"Your action will not be published to Facebook.";
                                      [[[UIAlertView alloc] initWithTitle:title
                                                      message:text
                                                     delegate:self
                                            cancelButtonTitle:@"OK!"
                                            otherButtonTitles:nil] show];
                                    } else {
                                      // Permission granted, publish the OG story
                                      [self publishStory];
                                    }

                                  } else {
                                    // There was an error, handle it
                                    // See https://developers.facebook.com/docs/ios/errors/
                                  }
                                }];

社交框架

-(void)requestPermissions
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    __block ACAccount *facebookAccount = nil;

    ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions
    NSDictionary *options = @{
                    ACFacebookAppIdKey: @"MYAPPID",
                    // READ permissions here (if any)
                    ACFacebookPermissionsKey: @[@"email"],
                    ACFacebookAudienceKey: ACFacebookAudienceFriends
   };

   [accountStore requestAccessToAccountsWithType:facebookAccountType
                                       options:options completion:^(BOOL granted, NSError *e)
   {
     if (granted) {

         NSDictionary *options2 = @{
                          ACFacebookAppIdKey: @"MYAPPID",
                          // PUBLISH permissions here
                          ACFacebookPermissionsKey: @[@"publish_actions"],
                          ACFacebookAudienceKey: ACFacebookAudienceFriends
         };
         [accountStore requestAccessToAccountsWithType:facebookAccountType options:options2 completion:^(BOOL granted, NSError *error) {
             if (granted) {
                 NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];

                 facebookAccount = [accounts lastObject];                 
             }
             else {
                 NSLog(@"Access denied 2");
                 NSLog(@"%@", [error description]);
             }
         }];
     } else {
         NSLog(@"Error: %@", [e description]);
         NSLog(@"Access denied");
     }
 }];
}