मैं उपयोगकर्ता से जुड़े Google खाते का उपयोग करने के लिए प्रमाणीकृत करने के साथ काम कर रहा हूं। समस्या यह है कि जब भी उपयोगकर्ता मेरे ऐप के माध्यम से लॉग इन करता है, तो "एक्सेस एक्सेस" हमेशा Google के प्रमाणीकरण दृश्य पर दिखाई देता है, फिर भी मैंने पिछले परीक्षण से पहले से एक्सेस एक्सेस पर क्लिक किया था। क्या यह सामान्य है या क्या मैं अपने कोड गलत कर रहा हूं? कृपया मुझे लोगों की मदद करो।आईओएस: Google प्रमाणीकरण कोड
- (IBAction)signIn:(id)sender {
if(!isSignedIn){
[self signOutFromAll];
NSString *keychainItemName = nil;
// save keychain
keychainItemName = kKeychainItemName;
NSString *scope = @"https://www.googleapis.com/auth/plus.me";
NSString *clientID = kClientID;
NSString *clientSecret = kClientSecret;
SEL finishedSel = @selector(viewController:finishedWithAuth:error:);
GTMOAuth2ViewControllerTouch *viewController;
viewController = [GTMOAuth2ViewControllerTouch controllerWithScope:scope
clientID:clientID
clientSecret:clientSecret
keychainItemName:keychainItemName
delegate:self
finishedSelector:finishedSel];
[[self navigationController]pushViewController:viewController animated:YES];
} else {
[self displayAlertWithMessage:@"Currently Signed in."];
} }
- (IBAction)signOut:(id)sender {
[self signOutFromAll];
[self displayAlertWithMessage:@"Signed out."]; }
इस प्रतिनिधि के लिए है:
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error{
if(error != nil){
// Authentication failed...
NSLog(@"Authentication error: %@", error);
NSData *responseData = [[error userInfo] objectForKey:@"data"];
if([responseData length] > 0)
NSLog(@"%@", [[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]autorelease]);
self.auth = nil;
} else {
// Authentication succeeded...
isSignedIn = YES;
self.auth = auth;
}
}
और awakeFromNib:
मैं एक बाहर में loggin के लिए निम्नलिखित कोड का उपयोग
- (void)awakeFromNib{
// Fill in the Client ID and Client Secret text fields
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// First, we'll try to get the saved Google authentication, if any, from the keychain
// Normal applications will hardcode in their client ID and client secret,
// But the sample app allows the user to enter them in a text field, and saves them in the preferences
NSString *clientID = [defaults stringForKey:kGoogleClientIDKey];
NSString *clientSecret = [defaults stringForKey:kGoogleClientSecretKey];
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
clientID:clientID
clientSecret:clientSecret];
if (auth.canAuthorize) {
// There is saved google authentication
// self.serviceSegments.selectedSegmentIndex = 0;
}
// Save the authentication object, which holds the auth tokens
self.auth = auth;
[self setAuth:auth];
isSignedIn = self.auth.canAuthorize;
}
रास्ता अपना संदर्भ तक इन कोडों के लिए इस लिंक पर है: http://code.google.com/p/gtm-oauth2/wiki/Introduction#Using_the_OAuth_2_Controllers
मैं "GTMOAuth2ViewControllerTouch * ViewController" में नहीं के बराबर मूल्य मिल गया हालांकि clientid, clientSecret, keychainItemName correct.Can आप explian यहाँ क्या गलत है कर रहे हैं? – Ponting