【问题标题】:Post image is no more working with new iOS Facebook SDK发布图片不再使用新的 iOS Facebook SDK
【发布时间】:2013-10-05 10:44:58
【问题描述】:

我添加了在 iOS6 上运行良好的功能,但在 iOS7 中,我不得不更新 Facebook SDK,因为旧版本中的 id 和 setId 被标记为非公开且未经验证。 所以,我用新的 SDK 替换了旧的 SDK,但当然,帖子图像不再工作(因为 id 肯定是未知的)。 我有这个:

[params setObject:textViewMessageFacebook.text forKey:@"message"];
[params setObject:UIImagePNGRepresentation(screenshot) forKey:@"picture"];

[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos", idAmiS]
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)

但不知道如何纠正它以使其正常工作... 谢谢

【问题讨论】:

  • 使用 SlCompser 控制器...
  • 你能检查一下你的权限数组部分吗,一切都好吗?

标签: iphone ios facebook ios7


【解决方案1】:

使用 SlComposer 控制器在 facebook 上发布图片。

1) 首先将社交框架和帐户框架添加到您的项目中,然后尝试以下代码

把这段代码写在你想要的地方...

    {
    ACAccountType *facebookTypeAccount = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];


        [accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                               options:@{ACFacebookAppIdKey: @"131740927031850", ACFacebookPermissionsKey: @[@"email"]}
                                            completion:^(BOOL granted, NSError *error) {
                                                if(granted){
                                                    NSArray *accounts = [accountStore accountsWithAccountType:facebookTypeAccount];
                                                    _facebookAccount = [accounts lastObject];
                                                    ACAccountCredential *fbCredential = [_facebookAccount credential];
                                                    accessToken = [fbCredential oauthToken];
                                                    NSLog(@"Facebook Access Token: %@", accessToken);
                                                    NSLog(@"Success");

                                                    [self facebook];
                                                }else{
                                                    NSLog(@"Fail");
                                                    NSLog(@"Error: %@", error);
                                                }
                                            }];

        if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
        {
            SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
            [tweetSheet setInitialText:@"posting from my own app! :)"];
            [tweetSheet addURL:[NSURL URLWithString:@"www.xyz.com"]];


// Here you add the image

             [tweetSheet addImage:[UIImage imageNamed:@"yourimage.png"]];




            [self presentViewController:tweetSheet animated:YES completion:nil];


        }
        else
        {
            UIAlertView *alertView = [[UIAlertView alloc]
                                      initWithTitle:@"Sorry"
                                      message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
                                      delegate:self
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];
            [alertView show];
        }


    }



    - (void)facebook
    {

        NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];
        NSLog(@"URl:-%@",meurl);
        SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                  requestMethod:SLRequestMethodGET
                                                            URL:meurl
                                                     parameters:nil];

        merequest.account = _facebookAccount;

        [merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
            NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

            NSLog(@"Parsed Data:-%@", meDataString);

        }];

    }

【讨论】:

    猜你喜欢
    • 2011-07-27
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2023-03-09
    • 1970-01-01
    • 2013-07-14
    相关资源
    最近更新 更多