I am working on an ios Application, recently I have got a new requirement for it i.e. to provide user a option to sign in with gmail . when user hit the sign in button then i want to open gmail login screen and after user enter his credentials , if the credentials are correct then instead of open his mail , i want the control to be navigate to my application home page . can anybody tell me how to achieve this
-
Hey r u able to integrate gmail into ur app.Please provide me a gud link.I tried ur answer but I get error Error Domain=com.google.GTMOAuth2 Code=-1001..When I go for a differnt code following this link http://technogerms.com/login-with-google-using-oauth-2-0-for-ios-xcode-objective-c/I get access token , but unable to retrieve user details with that access token – Honey Mar 01 '14 at 09:50
-
@arizah, what is ur email id , i can send u a sample – Shaik Riyaz Mar 03 '14 at 04:31
-
Ok please send it to the id in profile – Honey Mar 03 '14 at 05:20
-
@Kausar u r email id is not visible in ur profile . – Shaik Riyaz Mar 03 '14 at 07:48
-
Ok.Please mail to this hajirakausar21@gmail.com – Honey Mar 03 '14 at 08:07
-
@RIYAZ Hi i am trying to do the same but not able to get it done successfully.I am not getting any error but its not working properly. can you share some sample code or demo with me please to configure mails to my app. – ios developer Jul 18 '14 at 05:30
-
@ios yes of course i can share the code , send a test mail to skriyaz7@gmail.com – Shaik Riyaz Jul 18 '14 at 06:15
-
@RIYAZ Please Send it to my id rohan.sdcet@gmail.com – rohan thankur Jan 28 '15 at 10:31
-
Hi, I want to integrate gmail in my ios application, Please sugeest me if you have any sample code or link to sugeest. I had asked question here stackoverflow.com/questions/33624136/… . Please answer it If you can – Aarti Oza Nov 10 '15 at 07:01
2 Answers
Finally i found the solution . . .i think this will help anybody else Follow the below steps to integrate gmail with your application .
1.Add following classes to you project .
GTMHTTPFetcher.h , GTMHTTPFetcher.m ,GTMOAuth2Authentication.h, GTMOAuth2Authentication.m,GTMOAuth2SignIn.h,GTMOAuth2SignIn.m,GTMOAuth2ViewControllerTouch.h,GTMOAuth2ViewControllerTouch.m,GTMOAuth2ViewTouch.xib,SBJSON.h , SBJSON.m
you will get these classes here : https://github.com/jonmountjoy/Force.com-iOS-oAuth-2.0-Example
Note : if you are working under ARC Environment then you have to disable the ARC for following files :
GTMHTTPFetcher.m , GTMOAuth2Authentication.m , GTMOAuth2SignIn.m, GTMOAuth2ViewControllerTouch.m
To disable ARC for source files in Xcode 4, select the project and the target in Xcode. Under the target "Build Phases" tab, expand the Compile Sources build phase, select the library source files, then press Enter to open an edit field, and type -fno-objc-arc as the compiler flag for those files.
2. add the following frameworks
security.framework , systemConfiguration.framework
3. Register your app to google api console …. here : https://code.google.com/apis/console
Then go to ApiAccess section , create client id for iOS app . then you will get clientID, ClientSecret and RedirectUrl
*4. Now it's time for coding . . . .*
create a signIn button in your controller and set the action for that . Here when the user click the button SignInGoogleButtonClicked method gets called .
//import GTMOAuth2Authentication , GTMOAuth2ViewControllerTouch
#define GoogleClientID @"paster your client id"
#define GoogleClientSecret @"paste your client secret"
#define GoogleAuthURL @"https://accounts.google.com/o/oauth2/auth"
#define GoogleTokenURL @"https://accounts.google.com/o/oauth2/token"
-(void) SignInGoogleButtonClicked
{
NSURL * tokenURL = [NSURL URLWithString:GoogleTokenURL];
NSString * redirectURI = @"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication * auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"google"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:GoogleClientID
clientSecret:GoogleClientSecret];
auth.scope = @"https://www.googleapis.com/auth/plus.me";
GTMOAuth2ViewControllerTouch * viewcontroller = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth
authorizationURL:[NSURL URLWithString:GoogleAuthURL]
keychainItemName:@"GoogleKeychainName" delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[self.navigationController pushViewController:viewcontroller animated:YES];
}
//this method is called when authentication finished
- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController finishedWithAuth:(GTMOAuth2Authentication * )auth error:(NSError * )error
{
if (error != nil) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error Authorizing with Google"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert !"
message:@"success"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}

- 1,312
- 8
- 19

- 11,204
- 7
- 53
- 70
-
1i tried this olution step by step but not work not get any error. or also not get the gmail login window for that. – Jitendra Dec 04 '13 at 13:02
-
man the code is working for me , can you just cross check your code once . – Shaik Riyaz Dec 04 '13 at 13:17
-
ya this code works fine for me but how i get the details login information like facebook graph api they provide all the details... – Jitendra Dec 04 '13 at 13:19
-
error appeard when login the user error log is invalide user i am testing this on simulator... – Jitendra Dec 07 '13 at 08:58
-
1it working better but i getting error Error Domain=com.google.GTMOAuth2 Code=-1001 "The operation couldn’t be completed. (com.google.GTMOAuth2 error -1001.) – Muralikrishna Feb 14 '14 at 09:41
-
1
-
Hey is the problem of 1001 error solved.If so please provide me how, bcoz Im also facing the same problem – Honey Mar 01 '14 at 09:44
-
1I think you people should check your #define GoogleAuthURL @"" and #define GoogleTokenURL @"" ..... these codes are not correct – Omer Waqas Khan Oct 09 '14 at 11:36
-
@OmerWaqasKhan this are fixed url's provided in oAuth2 documentation provided by google – Shaik Riyaz Jun 08 '15 at 05:11
-
Hi, I want to integrate gmail in my ios application, Please sugeest me if you have any sample code or link to sugeest. I had asked question here http://stackoverflow.com/questions/33624136/retrive-friends-of-friends-in-gmail-for-ios-app Please answer it If you can – Aarti Oza Nov 10 '15 at 07:01
I found it. but then i am just able to fetch the snippet i.e first few words of e-mail body & not the whole . I just stopped coz i did not found any other way to do so. because i am using OAuth 2.0 .

- 419
- 1
- 9
- 16