我完成了谷歌在我的示例應用程序集成,而我試圖在我的項目中落實finishedWithAuth方法沒有調用。
0.its進入google +登錄屏幕。
1.i完成創建Oauth客戶端密鑰生成。
2.增加了gppsigninbutton。
3.in appdelegate.m文件
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if([FBSDKApplicationDelegate sharedInstance])
{
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
else
{
NSLog(@"entering");
return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
}
}
實施
- URL也加入的.plist。
這是我的代碼
signIn.delegate = self;
signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;
//signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user's email
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientId;
// signIn.clientID=APIID;
signIn.homeServerClientID = kClientId;
// Uncomment one of these two statements for the scope you chose in the previous step
// signIn.scopes = @[ kGTLAuthScopePlusLogin ]; // "https://www.googleapis.com/auth/plus.login" scope
// signIn.scopes = @[ @"profile" ]; // "profile" scope
signIn.scopes=[NSArray arrayWithObjects:kGTLAuthScopePlusLogin,kGTLAuthScopePlusMe, nil];
// Optional: declare signIn.actions, see "app activities"
[signIn trySilentAuthentication];
}
- (void)signOut {
[[GPPSignIn sharedInstance] signOut];
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
NSLog(@"Received error %@ and auth object %@",error, auth);
if(error)
{
}
else
{
NSString *serverCode = [GPPSignIn sharedInstance].homeServerAuthorizationCode;
NSLog(@"this is server code%@",serverCode);
NSLog(@"user email%@", signIn.authentication.userEmail);
NSLog(@"user id%@",signIn.authentication.userID);
NSLog(@"auth token=%@",auth.accessToken);
NSString *str = [NSString stringWithFormat:@"https://www.googleapis.com/oauth2/v1/userinfo?access_token=%@",auth.accessToken];
NSString* escapedUrl = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",escapedUrl]];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:url usedEncoding:nil error:nil];
NSData *data = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"this is jsonvalues==%@",json);
if (auth.userEmail)
{
[[[GPPSignIn sharedInstance] plusService] executeQuery:[GTLQueryPlus queryForPeopleGetWithUserId:@"me"] completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
{
// NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",person.image.url]];
// NSLog(@"%@",url);
// NSLog(@"Name:%@",person.displayName);
// NSLog(@"birthday:%@",person.birthday);
//
// NSLog(@"gender:%@",person.gender);
NSLog(@"peoplelist%@",person.displayName);
NSLog(@"peopleimae=%@",person);
// NSLog(@"people image%@",person.image);
// NSLog(@"people emailid%@",person.emails);
// imgurl = userData[@"picture"][@"data"][@"url"];
NSDictionary *dic=(NSDictionary *)person;
if(person.image)
{
NSLog(@"this is converted dictionary=%@",dic);
}
}];
// [self disconnect];
}
}
}
- (void)disconnect {
[[GPPSignIn sharedInstance] disconnect];
}
- (void)didDisconnectWithError:(NSError *)error {
if (error) {
NSLog(@"Received error %@", error);
} else {
// The user is signed out and disconnected.
// Clean up user data as specified by the Google+ terms.
}
}
添加一些代碼.... –
其中的代碼區你想老兄...... @ Anbu.Karthik –
@ Anbu.Karthik任何兄弟問題與clientID –