Objective c 通过twitter ios7登录
我希望用户能够通过Twitter登录,而不是填写注册表格,但是当用户点击“通过Twitter登录”时,我希望从Twitter API检索我需要的基本信息。虽然我不会为您编写代码,但您可以在这里开始您的旅程:Objective c 通过twitter ios7登录,objective-c,ios7,Objective C,Ios7,我希望用户能够通过Twitter登录,而不是填写注册表格,但是当用户点击“通过Twitter登录”时,我希望从Twitter API检索我需要的基本信息。虽然我不会为您编写代码,但您可以在这里开始您的旅程: Twitter提供了一种逐步使用其API的方法。如果您对此有任何问题,那么您可以在这里随时询问我们。您可以使用默认的社交框架 将社交框架添加到项目中。 然后将头Accounts/Accounts.h&Social/Social.h头添加到代码文件中 然后在添加下面的方法后,在需要时调用它
Twitter提供了一种逐步使用其API的方法。如果您对此有任何问题,那么您可以在这里随时询问我们。您可以使用默认的社交框架 将社交框架添加到项目中。 然后将头Accounts/Accounts.h&Social/Social.h头添加到代码文件中 然后在添加下面的方法后,在需要时调用它 代码:
- (void) getInfo
{
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: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];
// Filter the preferred data
NSString *screen_name = [(NSDictionary *)TWData objectForKey:@"screen_name"];
NSString *name = [(NSDictionary *)TWData objectForKey:@"name"];
int followers = [[(NSDictionary *)TWData objectForKey:@"followers_count"] integerValue];
int following = [[(NSDictionary *)TWData objectForKey:@"friends_count"] integerValue];
int tweets = [[(NSDictionary *)TWData objectForKey:@"statuses_count"] integerValue];
NSString *profileImageStringURL = [(NSDictionary *)TWData objectForKey:@"profile_image_url_https"];
NSString *bannerImageStringURL =[(NSDictionary *)TWData objectForKey:@"profile_banner_url"];
// Update the interface with the loaded data
nameLabel.text = name;
usernameLabel.text= [NSString stringWithFormat:@"@%@",screen_name];
tweetsLabel.text = [NSString stringWithFormat:@"%i", tweets];
followingLabel.text= [NSString stringWithFormat:@"%i", following];
followersLabel.text = [NSString stringWithFormat:@"%i", followers];
NSString *lastTweet = [[(NSDictionary *)TWData objectForKey:@"status"] objectForKey:@"text"];
lastTweetTextView.text= lastTweet;
// Get the profile image in the original resolution
profileImageStringURL = [profileImageStringURL stringByReplacingOccurrencesOfString:@"_normal" withString:@""];
[self getProfileImageForURLString:profileImageStringURL];
// Get the banner image, if the user has one
if (bannerImageStringURL) {
NSString *bannerURLString = [NSString stringWithFormat:@"%@/mobile_retina", bannerImageStringURL];
[self getBannerImageForURLString:bannerURLString];
} else {
bannerImageView.backgroundColor = [UIColor underPageBackgroundColor];
}
}
});
}];
}
} else {
NSLog(@"No access granted");
}
}];
}
你可以得到演示代码
https://github.com/nst/STTwitter
如果您正在使用pod,请在pod文件中使用write STTwitter并更新您的pod。问题是什么?您的意思是什么?不幸的是,我们无法为您编写代码。我提到我想在我的应用程序中通过twitter登录。我也知道dat您不会为我编写代码。是的,如果您需要任何其他API,一切都在这里:实际上我想通过twitter登录。你明白了吗?这段代码直接获取特定用户名的信息是的,这是因为你已经在你的twitter设置应用程序中添加了你的twitter凭据。你收到权限警报了吗?如果您还没有添加任何帐户,那么您将收到登录该应用程序的警告消息。如果您还需要澄清,请告诉我我收到了警报,但我想将其重定向到twitter的signit url