在iPhone中使用社交框架和帐户框架工作检索Twitter OAuth令牌?

时间:2014-01-13 13:00:19

标签: ios iphone ipad

我有一个应用程序在其中我正在进行Twitter登录以访问用户基本信息。我正在使用社交和帐户框架work.all工作正常,

`if([self userHasAccessToTwitter])
        {
        ACAccountStore *accountStore = [[ACAccountStore alloc] init];
        ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
        [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
            if (granted) {
                NSArray *accounts = [accountStore accountsWithAccountType:accountType];
                // Check if the users has setup at least one Twitter account
                if (accounts.count > 0)
                {
                    ACAccount *twitterAccount = [accounts objectAtIndex:0];
                    // Creating a request to get the info about a user on Twitter
                    SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/users/show.json"] parameters:[NSDictionary dictionaryWithObject:twitterAccount.username forKey:@"screen_name"]];
                    [twitterInfoRequest setAccount:twitterAccount];
                    // Making the request
                    [twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            // Check if we reached the reate limit
                            if ([urlResponse statusCode] == 429) {
                                NSLog(@"Rate limit reached");
                                return;
                            }
                            // Check if there was an error
                            if (error) {
                                NSLog(@"Error: %@", error.localizedDescription);
                                return;
                            }
                            // Check if there is some response data
                            if (responseData) {
                                NSError *error = nil;
                                NSArray *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];

                                NSString *profileImageStringURL = [(NSDictionary *)TWData objectForKey:@"profile_image_url"];

                                // Update the interface with the loaded data

                                [self getProfileImageForURLString:profileImageStringURL];
                            }
                        });
                    }];
                }
            }
`

但是,如果他没有在设置中配置任何帐户,我需要在Instagram中进行自定义登录,使用xAuth登录。任何人都可以帮助我,我已经完成了这个

  

Retrieving Twitter OAuth Token using Social Framework (iOS6)

但似乎没有什么比我更清楚,如何使用用户名和密码制作SLrequest来访问身份验证令并让他登录推特是pbm让我感到困惑。任何人都可以指导我吗?

0 个答案:

没有答案