我希望用戶能夠通過Twitter登錄而不是填寫註冊表單,但是當用戶點擊「通過Twitter登錄」時,我想從Twitter獲取所需的基本信息API。通過twitter登錄ios7
回答
雖然我不會爲你寫的代碼,你可以踏上你的旅程在這裏: https://dev.twitter.com/twitter-kit/ios/twitter-login
Twitter提供使用其API的一步一步的方式。如果你有任何問題,那麼你可以隨時在這裏問我們。
謝謝你威爾坎貝爾 –
是啊,如果你需要任何其他的API,這一切都在這裏:https://dev.twitter.com/overview/documentation – wkcamp
你可以使用默認的社會框架,
- 加入社會工作框架到您的項目。
然後爲您的代碼文件添加標頭
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");
}
}];
}
非常感謝你mucj先生尼勒什帕特爾。你從哪裏來?? –
印度,它在你的最後? –
實際上我想通過twitter登錄。你讓我? –
你可以演示代碼
https://github.com/nst/STTwitter
如果您使用的吊艙然後在POD文件中使用寫 「STTwitter」,並更新你吊艙。
我不使用pod –
你可以下載sdk手動並在代碼中使用 – kb920
- 1. 登錄/登錄通過twitter iOS7
- 2. 登錄通過Twitter
- 3. Omniauth通過Twitter登錄
- 4. 通過Twitter登錄Twitter數據庫Schema
- 5. 在ios上通過twitter實現登錄
- 6. Rails通過Twitter Bootstrap Navbar(w/Devise)登錄?
- 7. Python通過twitter登錄到網站
- 8. rauth/flask:如何通過Twitter登錄?
- 9. 通過twitter登錄的錯誤(modx)
- 10. 通過登錄
- 11. Twitter登錄Quickblox
- 12. Twitter登錄iOS6
- 13. 執行Twitter登錄(服務器端),並通過jquery/ajax獲取登錄結果
- 14. 錄音在iOS7通過AudioQueueStart功能
- 15. 登錄通過PHP
- 16. 通過twitter4j登錄
- 17. 登錄通過PayPal
- 18. 登錄通過VBA
- 19. 通過Android登錄
- 20. 通過Linkedin登錄
- 21. 通過iframe登錄
- 22. 通過HttpClient登錄
- 23. 通過php登錄
- 24. 通過Facebook登錄
- 25. 通過XHR登錄
- 26. 登錄通過單點登錄
- 27. 通過Facebook登錄後無法通過Facebook登錄
- 28. 通過Linq to Twitter使用OAuth登錄Twitter API後,如何獲取登錄用戶的UserID或ScreenName?
- 29. Twitter登錄崩潰
- 30. 使用twitter登錄
什麼問題? – Hazok
笏你的意思wats問題 –
不幸的是,我們不能爲你寫代碼。 – wkcamp