0

iOS 6 組み込みの Facebook SDK を使用して Facebook ユーザーの詳細を取得するにはどうすればよいですか? いくつかの例を試しましたが、うまくいきませんでした。

- (void) getFBDetails {

if(!_accountStore)
    _accountStore = [[ACAccountStore alloc] init];

ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                       options:@{ACFacebookAppIdKey: @"514284105262105", ACFacebookPermissionsKey: @[@"email"]}
                                    completion:^(BOOL granted, NSError *error) {
                                        if(granted){
                                            NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
                                            _facebookAccount = [accounts lastObject];
                                            NSLog(@"Success");

                                            [self me];

                                        }else{
                                            // ouch
                                            NSLog(@"Fail");
                                            NSLog(@"Error: %@", error);
                                        }
                                    }];


}


- (void)me{
NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];

SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                          requestMethod:SLRequestMethodGET
                                                    URL:meurl
                                             parameters:nil];

merequest.account = _facebookAccount;

[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

    NSLog(@"%@", meDataString);

}];

}

しかし、これは Facebook からデータを取得できません。私のアプリIDは正しいです。

これは私が得たエラーメッセージです

Error: Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: no stored remote_app_id for app" UserInfo=0x1d879c90 {NSLocalizedDescription=The Facebook server could not fulfill this access request: no stored remote_app_id for app} 
4

3 に答える 3

1

これで問題が解決するかどうかはわかりませんが、アプリの AppName-Info.plist ファイルに Facebook アプリ ID を設定しましたか?

必要なキーFacebookAppIDは で、タイプはStringです。そこにもアプリ ID を入力してみて、機能するかどうかを確認してください。

于 2013-01-09T04:47:16.287 に答える
0

iOS6.0 では、読み取り権限と書き込み権限を別々に要求する必要があります。最初に電子メールの読み取り権限を要求してから、アプリの要件に従って他の権限を要求します。

于 2013-09-09T11:28:48.627 に答える
0
in .h file

#import <Accounts/Accounts.h>
#import <Social/Social.h>

@property (nonatomic, strong) ACAccountStore *accountStore;
@property (nonatomic, strong) ACAccount *facebookAccount;

in .m file 

- (void) getuserdetails
{

    self.accountStore = [[ACAccountStore alloc]init];
    ACAccountType *FBaccountType= nil;
    //[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    if (! FBaccountType) {
        FBaccountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    }
    NSString *key =kFBAppId;
    NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];


    [self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
     ^(BOOL granted, NSError *e)
     {
         if (granted)
         {
             NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
             self.facebookAccount = [accounts lastObject];
             NSLog(@"facebook account =%@",self.facebookAccount);
             [self get];
         }
         else
         {
             NSLog(@"fb error %@",e.description);

             dispatch_async(dispatch_get_main_queue(), ^
                            {
                                [self performSelectorOnMainThread:@selector(hideLoader) withObject:nil waitUntilDone:YES];
                                NSLog(@"%@",e.description);
                                if([e code]== ACErrorAccountNotFound)
                                {
                                    UIAlertView* alt = [[UIAlertView alloc] initWithTitle:@"Account not found"
                                                                                  message:msgSetUpFBAccount delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
                                    [alt show];
                                }
                                else
                                {
                                    UIAlertView* alt = [[UIAlertView alloc] initWithTitle:msgFBAccessDenied
                                                                                  message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
                                    [alt show];
                                }

                            });
             NSLog(@"error getting permission %@",e);

         }
     }];
}

-(void)get
{

    NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me"];

    SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                            requestMethod:SLRequestMethodGET
                                                      URL:requestURL
                                               parameters:nil];
    request.account = self.facebookAccount;
    [request performRequestWithHandler:^(NSData *data,
                                         NSHTTPURLResponse *response,
                                         NSError *error)
     {

         if(!error)
         {
             list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

             NSLog(@"Dictionary contains: %@", list );


             if([list objectForKey:@"error"]!=nil)
             {
                 [self attemptRenewCredentials];
             }
             dispatch_async(dispatch_get_main_queue(),^{
             });

         }
         else
         {
             [self performSelectorOnMainThread:@selector(hideLoader) withObject:nil waitUntilDone:YES];
             NSLog(@"error from get%@",error);
         }

     }];


}



-(void)attemptRenewCredentials{
    [self.accountStore renewCredentialsForAccount:(ACAccount *)self.facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error){
        if(!error)
        {
            switch (renewResult) {
                case ACAccountCredentialRenewResultRenewed:
                    NSLog(@"Good to go");

                    [self get];
                    break;
                case ACAccountCredentialRenewResultRejected:
                {
                    NSLog(@"User declined permission");
                    UIAlertView* alt = [[UIAlertView alloc] initWithTitle:@"Access Denied"
                                                                  message:@"You declined permission" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
                    [alt show];
                    break;
                }
                case ACAccountCredentialRenewResultFailed:
                {
                    NSLog(@"non-user-initiated cancel, you may attempt to retry");
                    UIAlertView* alt = [[UIAlertView alloc] initWithTitle:@"Access Denied"
                                                                  message:@"non-user-initiated cancel, you may attempt to retry" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
                    [alt show];
                    break;
                }
                default:
                    break;
            }

        }
        else{
            //handle error gracefully
            NSLog(@"error from renew credentials%@",error);
        }
    }];


}

T**o get this code work the bundle Identifier with which you have registered your application with facebook and bundle identifier in application plist file should be same**
于 2015-01-07T17:05:49.217 に答える