1

Facebook共有をアプリに統合しようとしているだけです。アプリの最終製品はビデオであるため、最終的な編集物をアップロードして友人と共有することを念頭に置いています。アプリが機能するために、ACAccountフレームワークでネイティブソーシャルフレームワークを使用していますFacebook には、publish_stream パーミッションを要求する前に読み取りパーミッションを要求する必要があり、その直後 (どこかで読むこと) ができないという奇妙なロジックがあるようです。私のコード

    ACAccountStore* accountStore = [[ACAccountStore alloc] init];
NSDictionary *options = @{
                          ACFacebookAppIdKey: @"My app ID",
                          ACFacebookPermissionsKey: @[@"user_birthday"],
                          ACFacebookAudienceKey: ACFacebookAudienceOnlyMe
                          };
ACAccountType *facebookAccountType = [accountStore
                                      accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {

    if (granted) {

        NSArray *accounts = [accountStore
                             accountsWithAccountType:facebookAccountType];
         ACAccount * facebookAccount = [accounts lastObject];



        NSLog(@"access to facebook account ok %@", facebookAccount.username);

        NSData *videoData = [NSData dataWithContentsOfFile:[_fURL absoluteString]];
        NSLog(@"%@",[_fURL absoluteString]);
        NSLog(@"video size = %d", [videoData length]);
        NSDictionary *params = @{
                                 @"title": @"Me being silly",
                                 @"description": @"Me testing the video upload to Facebook with the new system."
                                 };

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

        [request addMultipartData:videoData
                         withName:@"source"
                             type:@"video/quicktime"
                         filename:[_fURL absoluteString]];
        request.account = facebookAccount;
        [request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response,NSError * error){
            NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

            NSLog(@"response = %@", responseString);
        }];

はい、ストリームの公開許可がありませんが、どこに配置すればよいかわかりません。このコード全体は、ユーザーがボタンを押したときに呼び出される 1 つのメソッドの下にあります。

4

1 に答える 1

0

とてもシンプルです。それが私の実装です:

- (void)requestAccessToFacebookAccountWithCompletionHandler:(QCFacebookCommunicatorCompletionHandler)completionHandler {
    [[self accountStore] requestAccessToAccountsWithType:[self accountType] options:[self facebookAccountAccessRequestOptionsForReadStreamPermission] completion:^(BOOL accessForReadingGranted, NSError *error) {
        if (accessForReadingGranted) {
            [[self accountStore] requestAccessToAccountsWithType:[self accountType] options:[self facebookAccountAccessRequestOptionsForPublishStreamPermission] completion:^(BOOL accessForWrittingGranted, NSError *error) {
                if (accessForWrittingGranted) {
                    completionHandler(YES, nil);
                } else {
                    completionHandler(NO, [error userInfo]);
                }
            }];
        } else {
            completionHandler(NO, [error userInfo]);
        }
    }];
}

オプション付きの辞書を返すヘルパーメソッドを使用するだけです。他のものはあなたのものと似ています。

次に、completionHandler 呼び出しの代わりに動画のアップロードを担当するコードを貼り付けるか、この実装を使用して、completionHandler でsuccess == YESの場合にのみ動画をアップロードできます。

それが役に立てば幸い!

于 2013-06-05T18:59:38.063 に答える