gpt4 book ai didi

iphone - Facebook Connect iPhone 问题

转载 作者:行者123 更新时间:2023-12-03 20:21:35 26 4
gpt4 key购买 nike

我正在使用Facebook Connect在我的应用程序上分享一些东西。因此,我想通过 UIACtionSheet 实现带有 2 个按钮的 Facebook Connect API,即“在 Facebook 上登录/共享”。

现在,我有一些问题:

假设我在 UIActionSheet 上有 2 个按钮,标题为“在 Facebook 上分享”“登录”。

我希望当用户登录 Facebook 时,我的登录按钮标题更改为“注销”。我知道我应该使用这个功能:

- (void)session:(FBSession*)session didLogin:(FBUID)uid {
//a code that change my login button title to LogOut
}

2- 我已登录 Facebook。当我要退出我的应用程序并再次打开应用程序时,我应该再次登录!我怎样才能防止这种情况发生?

3-最后我想将一些文本从 UIWebView 分享到 Facebook。我的 webview 导出名称为“myWeb”。如何将 Facebook Connect 与 UIWebView 连接起来进行共享?

我应该使用

-(void)publishFeed:(id)target 

最佳答案

#pragma mark FBDialog delegate methods
- (void)dialogDidSucceed:(FBDialog *)dialog {
if ([dialog isMemberOfClass:[FBLoginDialog class]]) {
NSLog(@"[FBLoginDialog::dialogDidSucceed] just did succeed");
} else if ([dialog isMemberOfClass:[FBPermissionDialog class]]) {
NSLog(@"[FBPermissionDialog::dialogDidSucceed] update user status");
[self facebookUpdateUserStatus];
}
}

- (void)dialogDidCancel:(FBDialog *)dialog {
}

- (void)dialog:(FBDialog *)dialog didFailWithError:(NSError *)error {
NSLog(@"dialog:%@ didFailWithError:%@", dialog, error);
}

#pragma mark FBSession delegate methods
- (void)session:(FBSession *)session didLogin:(FBUID)uid {
NSLog(@"User with id %lld logged in.", uid);
[self facebookCheckForPermission];
}

- (void)request:(FBRequest*)request didReceiveResponse:(NSURLResponse*)response {
NSLog(@"did r response");
}

- (void)request:(FBRequest*)request didLoad:(id)result {
if ([@"facebook.Users.hasAppPermission" isEqualToString: request.method]) {
if ([@"1" isEqualToString: result]) {
// post comment
NSLog(@"[Users.hasAppPermission::dialogDidSucceed] succeed, update status");
[self facebookUpdateUserStatus];
} else {
// show dialog
NSLog(@"[Users.hasAppPermission::dialogDidSucceed] fail, show dialog");
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = @"status_update";
[dialog show];
}
} else if ([@"facebook.Users.setStatus" isEqualToString: request.method]) {
if ([@"1" isEqualToString: result]) {
NSLog(@"facebook update did succeed");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Facebook"
message: @"L'article a bien été publié sur votre profil"
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
} else {
NSLog(@"facebook update did fail");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Facebook"
// Slava, change text here
message: @"Update did fail"
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
}
}

- (void)request:(FBRequest*)request didFailWithError:(NSError*)error {
NSLog(@"did fail: %@", [error localizedDescription]);
}

#pragma mark FBSession helper functions
- (FBSession *)fbSessionWithDelegate:(id)theDelegate {
if (nil != [FBSession session]) {
return [[FBSession session] retain]; // fuckup this leak =)
}

FBSession *session = [FBSession sessionForApplication: kFBAPIKeyEncoded
secret: kFBAPISecretEncoded
delegate: theDelegate];
return session;
}

- (void) facebookCheckForPermission {
NSLog(@"[facebookCheckForPermission] make a call");
NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys: @"status_update", @"ext_perm", nil];
// [[FBRequest requestWithDelegate: self] call: @"facebook.Users.hasAppPermission" params: d];
FBSession *fbSession = [self fbSessionWithDelegate: self];
[[FBRequest requestWithSession: fbSession delegate: self] call: @"facebook.Users.hasAppPermission" params: d];
}

- (void) facebookUpdateUserStatus {
NSLog(@"[facebookUpdateUserStatus] updating status");
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat: @"Je te recommande cet article: %@", postURL],
@"status", @"true", @"status_includes_verb", nil];
FBSession *fbSession = [self fbSessionWithDelegate: self];
updateRequest = [FBRequest requestWithSession: fbSession delegate: self];
[updateRequest call: @"facebook.Users.setStatus" params: params];
}

关于iphone - Facebook Connect iPhone 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2173649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com