0

我在 Facebook 开发人员控制台中为我的 iOS 应用程序创建了一个 Facebook 应用程序,但是当我使用该应用程序 ID 时,即使我得到成功的响应,它也不会被发布。请在下面找到我的代码。(即使我得到了那个特定帖子的 ID)

但关键是当我使用现有的 Facebook 应用程序 ID(当前用于我的实时应用程序)执行相同的代码时,这会被发布并且工作正常,所以我的假设是,我必须在 Facebook 应用程序配置中做一些事情开发者控制台,但我找不到。谁能给我一个线索?

提前致谢。

注意:我使用 iOS 6 社交框架

获取用户方法

    - (void)getUserAndShare {
    NSLog(@"Getting User");

    if(!_accountStore)
        _accountStore = [[ACAccountStore alloc] init];

    ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    [_accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                           options:@{ACFacebookAppIdKey: @"xxxxxxxxxxxxxx", ACFacebookPermissionsKey: @[@"email"]}
                                        completion:^(BOOL granted, NSError *error) {
                                            if(granted){
                                                NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
                                                _facebookAccount = [accounts lastObject];
                                                NSLog(@"Success account");

                                                [_accountStore renewCredentialsForAccount:_facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
                                                    if (error){

                                                    }

                                                    [self postPhoto:nil];
                                                }];


                                            }
                                        }];

}

分享方式

-(IBAction)postPhoto{

    if(!_accountStore)
        _accountStore = [[ACAccountStore alloc] init];

    NSDictionary *parameters = @{@"message": @"this is a resource picture 2", ACFacebookAppIdKey: @"xxxxxxxxxxxxxx"};

    SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                    requestMethod:SLRequestMethodPOST
                                                              URL:[NSURL URLWithString:@"https://graph.facebook.com/me/photos"]
                                                       parameters:parameters];

    NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"sec.jpg"]);
    [facebookRequest addMultipartData: data
                             withName:@"source"
                                 type:@"multipart/form-data"
                             filename:@"msg.jpg"];

    facebookRequest.account = _facebookAccount;

    [facebookRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
     {
         if (error) {
         }
         else
         {
             NSLog(@"Post successful");
             NSString *dataString = [[NSString alloc] initWithData:responseData encoding:NSStringEncodingConversionAllowLossy];
             NSLog(@"Response Data: %@", dataString);
         }
     }];
}

编辑:调用时是否需要请求特殊权限才能使用图形 API requestAccessToAccountsWithType

4

2 回答 2

1

最后我让它工作了,我的假设是正确的:) 当我请求访问时,我必须添加新的权限。所以正如我所说,它在我以前的 Facebook 应用程序 ID 中有效,那是因为我已经授予了该应用程序的权限。无论如何,对于那些有兴趣了解解决方案的人,请在下面找到它,

 //Specify App ID and permissions
    NSDictionary *options = @{
                              ACFacebookAppIdKey: @"xxxxxxxxxxxxxxx",
                              ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
                              ACFacebookAudienceKey: ACFacebookAudienceFriends
                              };

请求了两个新的权限publish_streampublish_actions

于 2013-07-31T05:09:55.843 回答
0

我认为问题出在您的 MIME 类型上,这一行的问题是:

[facebookRequest addMultipartData: data
                             withName:@"source"
                                 type:@"multipart/form-data"
                             filename:@"msg.jpg"];

将其更改为:

[facebookRequest addMultipartData:data
                       withName:@"media"
                           type:@"image/jpeg"
                       filename:@"msg.jpg"];
于 2013-07-30T18:37:56.003 回答