1

Facebookアカウントにテキストを投稿する簡単なプロトタイプを作成しようとしています。iOS 6 Facebook 統合ドキュメントを読み、次のコードを思いつきました。メソッド postTextToFacebook で SLRequest オブジェクトを作成し、ハンドラー ブロックで performRequestWithHandler を実行しようとする最後のブロックに到達するまで、すべてが正常に機能しているようです。ハンドラー ブロック内で制御が実行されることはありません。この場合、 performRequestWithHandler 呼び出しが成功しないと想定しています。成功した人はいますか?参照用のコードを次に示します。

#import <Social/Social.h>
#import "ViewController.h"

@implementation ViewController
@synthesize facebookAccount;
@synthesize accountStore;
@synthesize textToPost;

- (void)viewDidLoad
{
    [super viewDidLoad];


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}


-(IBAction) postToFacebook:(id)sender
{
    self.statusLabel.text = @"Logging in ...";
    if(self.accountStore == nil)
    {
        self.accountStore = [[ACAccountStore alloc] init];
    }

    ACAccountType *facebookAccountType = [self.accountStore enter code hereaccountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    NSMutableDictionary *myOptions = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                    @"172197712918906", ACFacebookAppIdKey,
                                    [NSArray arrayWithObjects:@"email", @"user_about_me", @"user_likes", nil], ACFacebookPermissionsKey, ACFacebookAudienceFriends, ACFacebookAudienceKey, nil];
    [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:myOptions completion:^(BOOL granted, NSError *error){
        __block NSString *statusText;
        if(granted)
        {
            NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
            self.facebookAccount = [accounts lastObject];
            [myOptions setObject:[NSArray arrayWithObjects:@"publish_stream", nil] forKey:ACFacebookPermissionsKey];
            [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:myOptions completion:^(BOOL granted, NSError *error) {
                 __block NSString *statusText1;
                if(granted && error == nil)
                {
                    NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
                    self.facebookAccount = [accounts lastObject];
                    [self postTextToFacebook];
                    statusText1 = @"Text Posted.";
                }
                else{
                    statusText1 = @"Publish Failed.";
                }

                dispatch_async(dispatch_get_main_queue(), ^{
                    self.statusLabel.text = statusText1;
                });
            }];
        }
        else{
            statusText = @"Login Failed.";
            NSLog(@"Error = %@",error);
        }


    }];

}

-(void) postTextToFacebook
{
    NSDictionary *parameters = @{@"message":self.textToPost.text};
    NSURL *feedURL = [NSURL URLWithString:@"https://graphs.facebook.com/me/feed"];

    SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:parameters];

    request.account = self.facebookAccount;

    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {        
        NSLog(@"Facebook request received, status code %d", urlResponse.statusCode);
        NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
        NSLog(@"Response data: %@", response);

        //handle errors
        if(error == nil)
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.statusLabel.text = @"text posted to facebook";
            });
        }

    }];
}

@end
4

1 に答える 1

2

あなたのURLは

https://graph.facebook.com/me/feed

それ以外の

https://graphs.facebook.com/me/feed

私は同じ問題を抱えていて、NSURLErrorDomain -1003 エラーが発生しました。

于 2013-02-07T09:52:24.923 に答える