[英]Facebook - ios integration (Social Framework) Invalid permission
I'm working on two different iOS apps: 我正在使用两个不同的iOS应用程序:
So I'm doing anything wrong despite I've tried to follow all kind of posts, docs, and so on. 因此,尽管我尝试关注所有类型的帖子,文档等等,但我还是做错了任何事情。
I've specially followed this post iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" error , it has a very good answer. 我特别关注了此发布iOS 6 Facebook的发布过程,最终结果为“ remote_app_id与存储的ID不匹配”错误 ,它具有很好的答案。
I think I have created my apps in Facebook Developers ok because I had problems (wrong iPhone ID and error 7) and following the post I've mentioned these problems dissapeared. 我想我已经在Facebook Developers中创建了我的应用程序,因为我遇到了问题(错误的iPhone ID和错误7),并且在发帖之后,我提到这些问题都消失了。
When a user clicks on share on facebook I do this: 当用户单击Facebook上的共享时,我这样做:
- (void) loginWithFacebookWithReadPermissionsWithDelegate:(id<IfcRRSSDelegate>)_delegate
{
self.delegateFB = _delegate;
ACAccountStore *account = [[ACAccountStore alloc]init];
ACAccountType *accountType = [cuenta accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *facebookKey = MY_FACEBOOK_KEY;
NSMutableArray *permimssions = [[NSMutableArray alloc] init];
[permimssions addObject:@"email"];
self.fbPermission = [NSMutableDictionary dictionaryWithObjectsAndKeys:
facebookKey, ACFacebookAppIdKey,
ACFacebookAudienceFriends, ACFacebookAudienceKey,
permimssions, ACFacebookPermissionsKey,
nil];
[account requestAccessToAccountsWithType:accountType options:self.fbPermission completion:
^(BOOL granted, NSError *error) {
if(granted)
{
NSArray *accounts = [account accountsWithAccountType: accountType];
ACAccount *_facebookAccount = [accounts lastObject];
self.accountFB = _facebookAccount;
ACAccountCredential *credentials = [self.accountFB credential];
self.tokenFB = [credentials oauthToken];
}
else
{
// Show error
}
}];
}
If this login goes well (in fact it always goes well) I call this: 如果此登录正常(实际上总是正常),我称之为:
- (void) loginWithFacebookWithWritePermissionsWithDelegate:(id<IfcRRSSDelegate>)_delegate
{
self.delegateFB = _delegate;
ACAccountStore *account = [[ACAccountStore alloc]init];
ACAccountType *accountType = [cuenta accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *facebookKey = MY_FACEBOOK_KEY;
NSMutableArray *permimssions = [[NSMutableArray alloc] init];
[permimssions addObject:@"publish_stream"];
[permimssions addObject:@"publish_actions"];
self.fbPermission = [NSMutableDictionary dictionaryWithObjectsAndKeys:
facebookKey, ACFacebookAppIdKey,
ACFacebookAudienceFriends, ACFacebookAudienceKey,
permimssions, ACFacebookPermissionsKey,
nil];
[account requestAccessToAccountsWithType:accountType options:self.fbPermission completion:
^(BOOL granted, NSError *error) {
NSLog(@">>>>ERROR: %@", error);
if(granted)
{
NSArray *accounts = [account accountsWithAccountType: accountType];
ACAccount *_facebookAccount = [accounts lastObject];
self.accountFB = _facebookAccount;
ACAccountCredential *credentials = [self.accountFB credential];
self.tokenFB = [credentials oauthToken];
}
else
{
// Show error
}
}];
}
This second login FAILS, I get this error: 第二次登录失败,出现此错误:
ERROR: Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: Invalid permission: publish_stream" UserInfo=0xc18d700 {NSLocalizedDescription=The Facebook server could not fulfill this access request: Invalid permission: publish_stream}
错误:错误Domain = com.apple.accounts代码= 7“ Facebook服务器无法满足此访问请求:无效的权限:publish_stream” UserInfo = 0xc18d700 {NSLocalizedDescription = Facebook服务器无法满足此访问请求:无效的权限:publish_stream}
Invalid permission: publish_stream??? 无效的权限:publish_stream ??? I can hardly find information about this error.
我几乎找不到有关此错误的信息。
I've tried to comment this permission and have only publish_action, but when I try to post I get this new error: 我试图对此权限发表评论,并且只有publish_action,但是当我尝试发布时,出现了这个新错误:
{
code = 200;
message = "(#200) The user hasn't authorized the application to perform this action";
type = OAuthException;
}
If this second login went well I would call this code to post (but it's never called because the second login fails): 如果第二次登录顺利,我将调用此代码进行发布(但由于第二次登录失败而从未调用):
- (void) postWithFacebookWithMessage:(NSString *)msg
{
if(self.accountFB)
{
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject: self.accountFB.credential.oauthToken forKey:@"access_token"];
[parameters setObject:msg forKey:@"message"];
NSURL *requestUR = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:requestURL
parameters:parameters];
request.account = self.accountFB;
[request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
if(!error)
{
NSDictionary *list = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if([list objectForKey:@"error"] != nil)
{
// Try to attempt Renew Credentials
}
else
{
// Everything works
}
dispatch_async(dispatch_get_main_queue(),^{});
}
else
{
// Try to attempt Renew Credentials
}
}];
}
}
If this is important, I've checked in my facebook page, in my activity, apps, this app and it sais "This app can publish in your name for: Only you". 如果这很重要,我已经在我的Facebook页面,活动,应用程序,此应用程序中检入,并说“该应用程序可以您的名义发布:只有您自己”。
Any idea of what is it happening? 知道发生了什么吗?
Kind regards! 亲切的问候!
EDIT: Sorry, I made an important mistake explaining the error so I edited the post: the facebook call that fails is the second login, not the post. 编辑:对不起,我在解释错误时犯了一个重要错误,所以我编辑了帖子:失败的Facebook调用是第二次登录,而不是帖子。
Try this code, which I using in my app: 试试我在我的应用程序中使用的这段代码:
__block ACAccount * facebookAccount;
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
NSDictionary *emailReadPermisson = @{
ACFacebookAppIdKey : @"0123456789",
ACFacebookPermissionsKey : @[@"email"],
ACFacebookAudienceKey : ACFacebookAudienceEveryone,
};
NSDictionary *publishWritePermisson = @{
ACFacebookAppIdKey : @"0123456789",
ACFacebookPermissionsKey : @[@"publish_actions"],
ACFacebookAudienceKey : ACFacebookAudienceEveryone
};
ACAccountType *facebookAccountType = [accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
//Request for Read permission
[accountStore requestAccessToAccountsWithType:facebookAccountType options:emailReadPermisson completion:^(BOOL granted, NSError *error) {
if (granted) {
NSLog(@"Granted for read");
//Request for write permission
[accountStore requestAccessToAccountsWithType:facebookAccountType options:publishWritePermisson completion:^(BOOL granted, NSError *error) {
if (granted) {
NSLog(@"Granded for post");
NSArray *accounts = [accountStore
accountsWithAccountType:facebookAccountType];
facebookAccount = [accounts lastObject];
NSLog(@"Successfull access for account: %@", facebookAccount.username);
/* Do any things here */
}
else
{
NSLog(@"Access to Facebook is not granted");
// Fail gracefully...
NSLog(@"%@",error.description);
}
}];
}else{
/* Error */
}
}];
This sample was found in this post 此样本在此帖子中找到
And if you're getting 'not granted' state of your account - check does your app not blocked in Settings->Facebook
. 如果您的帐户状态为“未授予”,请检查您的应用程序是否在
Settings->Facebook
未被阻止。 If it is - ask user to give access from settings. 如果是-要求用户授予设置访问权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.