使用Graph API iPhone发布到Facebook

编程入门 行业动态 更新时间:2024-10-28 16:18:35
本文介绍了使用Graph API iPhone发布到Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经实现了下面的示例代码来获取与用户feed的连接。

i have implemented this sample code below to get a connection to the user feed post

- (void)viewDidLoad { [super viewDidLoad]; facebook = [[Facebook alloc] initWithAppId:@"197765190297119" andDelegate:self]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; }

此示例代码在用户登录...它现在通过按下按钮进行检查来调用,但是dosent可以做任何操作,也许我可以得到一个对话框提示

and this sample code is called when the user logs in... it calls now by a button pressed for check, but dosent do any, perhaps i can get a dialog feed insted

NSString *str=@"Your String to post"; NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: str,@"message", @"Test it!",@"name", nil]; Facebook *fb = [[Facebook alloc] init]; [fb requestWithGraphPath:@"me/feed" // or use page ID instead of 'me' andParams:params andHttpMethod:@"POST" andDelegate:self];

推荐答案

这是一个将图像上传到Facebook的演练壁。我复制了这个旧的应用程序,目前的Facebook API工作有点不同。我想你可以看到我使用一个共享的Facebook对象的主要观点,您可以使用它来进行身份验证以及对API的请求。我拿出几件东西,使其更容易理解。苹果实际上希望您检查现有的互联网连接。我希望它有帮助。

This is a walkthrough of uploading an image to the facebook wall. I copied this out of an older application, the current facebook API works a little bit different. I think you can see my main point of using a shared facebook object, which you use to do the authentication and also the requests to the API. I took out a few things to make it easier to understand. Apple actually wants you to check for an existing internet connection. I hope it helps.

@synthesize facebook; //login with facebook - (IBAction) facebookButtonPressed { if (!facebook || ![facebook isSessionValid]) { self.facebook = [[[Facebook alloc] init] autorelease]; NSArray *perms = [NSArray arrayWithObjects: @"read_stream", @"create_note", nil]; [facebook authorize:FACEBOOK_API_KEY permissions:perms delegate:self]; } else { [self fbDidLogin]; } } //upload image once you're logged in -(void) fbDidLogin { [self fbUploadImage]; } - (void) fbUploadImage { NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys: resultImage, @"picture", nil]; [facebook requestWithMethodName: @"photos.upload" andParams: params andHttpMethod: @"POST" andDelegate: self]; self.currentAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Facebook", @"") message:NSLocalizedString(@"Uploading to Facebook.", @"") delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease]; [self.currentAlertView show]; } //facebook error - (void)request:(FBRequest*)request didFailWithError:(NSError*)error { [self.currentAlertView dismissWithClickedButtonIndex:0 animated:YES]; self.currentAlertView = nil; UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", @"") message:NSLocalizedString(@"Facebook error message", @"") delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [myAlert show]; [myAlert release]; } //facebook success - (void)request:(FBRequest*)request didLoad:(id)result { [self.currentAlertView dismissWithClickedButtonIndex:0 animated:YES]; self.currentAlertView = nil; UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Facebook", @"") message:NSLocalizedString(@"Uploaded to Facebook message", @"") delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [myAlert show]; [myAlert release]; }

更多推荐

使用Graph API iPhone发布到Facebook

本文发布于:2023-10-11 14:00:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:API   Graph   Facebook   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!