Sta*_*tas 27 iphone facebook objective-c
我正在尝试执行一个简单的发布过程:
- (IBAction)directPostClick:(id)sender {
self.statusLabel.text = @"Waiting for authorization...";
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = @[@"publish_stream", @"user_checkins", @"publish_checkins", @"user_likes", @"user_videos"];
NSDictionary * dict = @{ACFacebookAppIdKey : @"My app id here", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceOnlyMe};
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
__block NSString * statusText = nil;
if (granted) {
statusText = @"Logged in";
NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
NSLog(@"account is: %@", self.facebookAccount);
self.statusLabel.text = statusText;
[self postToFeed];
}
else {
self.statusLabel.text = @"Login failed";
NSLog(@"error is: %@", error);
}
}];
}
Run Code Online (Sandbox Code Playgroud)
编辑: 问题是,当我点击alertView的确定按钮(不允许也不工作)没有任何反应!- 这个行为现在改变了这个 iOS 6 Facebook发布程序最终"remote_app_id与存储的id不匹配"所以而不是"没有发生"我有一个错误"Facebook服务器无法满足此访问请求:remote_app_id确实不匹配存储的ID"
所以,似乎警报视图的点击处理程序什么都不做,我的completionHandler永远不会被调用.我确实有类似的问题:iOS 6社交集成 - 转到设置问题 我认为这是同样的问题.你们怎么看待它?PS我正在使用最新的xcode 4.5(4G182)和使用iPhone 6.0模拟器的MAC mini,OS X 10.8.1上运行.
补充:根据Bjorn的要求添加postToFeed
方法虽然从未调用过:
- (void)postToFeed {
NSDictionary * parameters = @{@"message" : @"Hello world!"};
NSURL * feedUrl = [NSURL URLWithString:@"https://graph.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) {
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Posted!";
});
}];
}
Run Code Online (Sandbox Code Playgroud)
Bjö*_*ser 97
使用Accounts Framework和Facebook集成时,我也遇到了一些困难.这是我学到的以及如何使它发挥作用.
1.确保您已正确设置Facebook上的应用程序
您需要设置应用程序与Facebook集成到Native iOS App的方式,并将应用程序的Bundle ID输入指定的字段.(编辑:请注意,捆绑ID区分大小写)您现在可以将iTunes ID设置为0.启用Facebook登录并将高级设置选项卡中的应用类型设置为Native/Desktop.
也设置在客户端应用秘密到无.
如果未正确设置这些选项中的一个或多个,则很可能会出现错误The Facebook server could not fulfill this access request: remote_app_id does not match stored id
.
(编辑:您还必须确保禁用沙箱.)
2.
首次安装Facebook应用程序首次通过iOS(以及Mac OS X)上的本机Facebook集成安装应用程序时,您必须仅要求基本的读取权限!闲来无事的email
,user_birthday
并且user_location
被允许在这里.user_about_me
根据Facebook文档使用,这也是一个基本的读取权限,不起作用.如果您之前使用的是Facebook JavaScript SDK或Facebook PHP SDK,那将非常令人困惑,因为它默认情况下会要求基本权限,而您无需执行某些操作.Facebook还通过一个关于如何在iOS 6上使用新的Facebook SDK的简短分步指南更新了他们的文档.
3.请求其他权限
重要的是要知道,您可能不会同时要求读写权限.这也是经验丰富的Facebook SDK开发人员可能会感到困惑的事情.请求read_stream
权限以及publish_stream
权限将使请求失败,从而导致错误应用程序可能无法同时获取读取和写入权限.
由于Facebook没有真正区分权限参考中的读/写权限,因此您必须自己识别写权限.他们通常带有manage_*
,publish_*
,create_*
或后缀*_management
.
Facebook也不建议在获得基本权限后立即要求其他权限.该文件说:"你现在必须要求阅读并单独发布许可(和顺序).最有可能的,你会要求读取权限的个性化时,应用程序启动和用户之后,如果合适的话,第一次登录,您的应用程序可以在打算将数据发布到Facebook时请求发布权限.[...]单独询问这两种类型也会大大提高用户授予发布权限的机会,因为您的应用程序只会在需要时搜索它们他们,很可能是当用户有更强烈的意图时."
4.示例代码
以下示例代码应适用于iOS和Mac OS X:
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// At first, we only ask for the basic read permission
NSArray * permissions = @[@"email"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"My app id here", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if (granted && error == nil) {
/**
* The user granted us the basic read permission.
* Now we can ask for more permissions
**/
NSArray *readPermissions = @[@"read_stream", @"read_friendlists"];
[dict setObject:readPermissions forKey: ACFacebookPermissionsKey];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if(granted && error == nil) {
/**
* We now should have some read permission
* Now we may ask for write permissions or
* do something else.
**/
} else {
NSLog(@"error is: %@",[error description]);
}
}];
} else {
NSLog(@"error is: %@",[error description]);
}
}];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22189 次 |
最近记录: |