1

このコードを使用して、Facebookニュースフィードでアイテムを共有しています。

-(void)recommendOnFacebook:(Item *)currentItem{    
if(!facebook){
    facebook = [[Facebook alloc] initWithAppId:@"myappid" andDelegate:self];
} 
NSMutableDictionary *params2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                [NSString stringWithFormat:@"%@", currentItem.name], @"name",
                                [shop name], @"caption",
                                currentItem.description, @"description",
                                [NSString stringWithFormat:@""], @"link",
                                currentItem.imagePath, @"picture",
                                nil, @"actions",
                                nil];    
[facebook dialog:@"feed" 
     andParams:params2
     andDelegate:self];
}

ログインしている場合は、フィードを共有するためのダイアログが正常に表示されます。しかし、私がログインしていない場合、このコードブロックが終了した後、APIダイアログは私の資格情報を要求します。私が必要としているのは、ユーザーがログインしていない場合、APIがダイアログを表示し、ユーザーが正常にログインした後、進行状況の共有を続行するために別のダイアログが表示されることです。

4

1 に答える 1

2

FBSessionDelegateを確認する必要があります。これが共有するための私のコードです

- (IBAction) facebookShare:(id)sender {
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    if (![delegate.facebook isSessionValid]) {
        [delegate.facebook authorize:[NSArray arrayWithObjects:@"publish_stream", @"offline_access", nil]];
    }
    else {
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
         [NSString stringWithFormat:@"TEXT", score.text], @"name",
         @"", @"caption",
         @"DESC.", @"description",
         @"link", @"link",
         @"imagelink", @"picture",
         nil];  
        [delegate.facebook dialog:@"feed"
               andParams:params
             andDelegate:self];
    }

}

#pragma mark - FB Session Delegate

- (void)fbDidLogin {
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    /*NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[delegate.facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[delegate.facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];*/
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
         [NSString stringWithFormat:@"TEXT", score.text], @"name",
         @"", @"caption",
         @"DESC.", @"description",
         @"link", @"link",
         @"imagelink", @"picture",
         nil];  
        [delegate.facebook dialog:@"feed"
               andParams:params
             andDelegate:self];
}

編集

パブリックカフェの場合のログアウトの場合、FBセッションデリゲートメソッドfbDidLoginのようにアクセストークンをNSUSerDefaultsに保存しないようにする必要があります。

FBDialogDelegateメソッドを実装するようになりました

- (void)dialogDidComplete:(FBDialog *)dialog {
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [delegate.facebook logout:self];
}
于 2012-05-18T11:37:12.097 に答える