#class GPPSignInButton;
I don't want use the GPPSignInButton for login and authentication i want to use my custom button when i pressed then the login process will start and the login with the Forcefully webview like facebook did it is possible in Google+ login too?
like the "Using the OAuth 2 Controllers"
Thanks in advance
anyhelp will be appreciated.
Yes you can use any UIButton instead of using GPPSignInButton.
Initialise the Google+ sdk in viewDidLoad using :
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to not get the user's email
signIn.clientID = kClientId;
signIn.scopes = [NSArray arrayWithObjects:kGTLAuthScopePlusMe,kGTLAuthScopePlusLogin, nil];
signIn.delegate = self;
Now in the uibutton action
- (IBAction)googlePlusSignIn:(id)sender
{
GPPSignIn *signIn = [GPPSignIn sharedInstance];
if([[GPPSignIn sharedInstance] authentication])
{
[signIn trySilentAuthentication];
}
else
{
// This is method that opens the G+ sign view
[signIn authenticate];
}
}
Add URL type and URL scheme in Targets -> Info -> URL Types .
Then add the following in App Delegate
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
Is there a way to provide user email to GPPSignIn object before calling [self.signIn authenticate]; so user wouldn't have to enter it in browser/Google Plus app to login in using Google account? I want to pass user email to the login form so the user had only to enter the password. I ask user for email earlier, so in most scenarios I can use it to help him login in fewer steps. self.signIn.userEmail is read-only so won't help me much.
user need to enter email and password if its the first time else doesn't have to.
- (IBAction)Btn_gogleShare:(id)sender {
if ([[GPPSignIn sharedInstance] authentication]) {
NSLog(#"share");
[self GoogleShare];
} else {
NSLog(#"Login");
[self GoogleLogin];
}
}
#pragma mark - Google+ ALL ACTIVITY
#pragma mark - Google+ Login
- (void)GoogleLogin{
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = 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.scopes = #[ kGTLAuthScopePlusLogin ];
//signIn.scopes = #[ #"profile" ]; // "profile" scope
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
[signIn authenticate];
[self showLoadingView:#"Authorizing..."];
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
NSLog(#"Received error %# and auth object %#",error, auth);
// NSLog(#"%#", signIn.authentication.userEmail);
[self hideLoadingView];
[self GoogleShare];
}
#pragma mark - Google+ share
- (void)GoogleShare{
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
// This line will fill out the title, description, and thumbnail from
// the URL that you are sharing and includes a link to that URL.
[shareBuilder setURLToShare:[NSURL URLWithString:#"https://www.example.com/restaurant/sf/1234567/"]];
[shareBuilder open];
}
#pragma mark - Google+ signOut
- (void)signOut {
[[GPPSignIn sharedInstance] signOut];
}
logout from google plus I used disconnect method but after that sign in app directly goes to permission page. Doesn't ask for Login. why?
here is my Sign In function
-(google*) MethodgoogleLogin
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"gotGoogleErrorAppClosed" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(gotGoogleErrorAppClosed:) name:#"gotGoogleErrorAppClosed" object:nil];
obj_google = [[google alloc]init];
personName=[[GTLPlusPersonName alloc]init];
// google + code
signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserID = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.clientID = #"384945330563-pcls0t8c28s1jf7qiod9555sg7edfqhj.apps.googleusercontent.com";
signIn.scopes = #[ kGTLAuthScopePlusLogin ];
signIn.delegate = obj_google;
[signIn authenticate];
return obj_google;
}
here is my sign out function
-(void)signOut
{
[signIn disconnect];
[signIn signOut];
}
You can use the signOut method of the GPPSignIn object to sign out your user, for example:
- (void)signOut {
[[GPPSignIn sharedInstance] signOut];
}
and after this revoke the token and disconnect the app.
For more information visit this:- https://developers.google.com/+/mobile/ios/sign-in#sign_out_the_user
I integrated Google+ sharing in my app. It works find few days ago but from last 3-4 days, it stops sharing means it does not show any prefilltext or image,etc. just shows blank share.
My code is as follow:
<GPPShareBuilder> shareBuilder = [[GPPShare sharedInstance] shareDialog];
[shareBuilder setTitle:#"Share" description:#"sharing" thumbnailURL:[NSURL URLWithString:#"http://25.media.tumblr.com/tumblr_m9p3n1vJmZ1rexr16o1_400.jpg"]];
[shareBuilder setContentDeepLinkID:#"rest=1234567"];
[shareBuilder open];
I don't know why this happen? Help me to solve this.
Try this
- (void)shareOnGooglePlus:(NSDictionary *)content
{
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.clientID = (NSString *) TempGoogleClientID;
signIn.scopes = [NSArray arrayWithObjects:
kGTLAuthScopePlusLogin,GooglePlusScopeProfile,GooglePlusScopeEmail,GooglePlusScopeMe,nil];
signIn.shouldFetchGoogleUserEmail = TRUE;
//[signIn authenticate];
id<GPPShareBuilder> shareBuilder = [[GPPShare sharedInstance] shareDialog];
[GPPShare sharedInstance].delegate = self;
[shareBuilder setURLToShare:content[URLKey]];
[shareBuilder setPrefillText:content[FeedTitleKey]];
[shareBuilder open];
}
I want to get friends(People) list from Google+ in iOS app.
I am using Google+ api tutorial given in link
https://developers.google.com/+/mobile/ios/getting-started
I am created new project on Google+ Developer Console the link is
https://console.developers.google.com/project
Getting following error in -(void)getPeopleInfo.
[lvl=3] __31-[ViewController getPeopleInfo]_block_invoke() Error: Error Domain=com.google.GTLJSONRPCErrorDomain Code=401 "The operation couldn’t be completed. (Invalid Credentials)" UserInfo=0x14d89340 {error=Invalid Credentials, GTLStructuredError=GTLErrorObject 0x14d855e0: {message:"Invalid Credentials" code:401 data:[1]}, NSLocalizedFailureReason=(Invalid Credentials)}
2014-03-13 12:40:21.026 GPlusDemo[636/0x3d35718c] [lvl=3] __31-[ViewController getPeopleInfo]_block_invoke() Error: Error Domain=com.google.GTLJSONRPCErrorDomain Code=401 "The operation couldn’t be completed. (Invalid Credentials)" UserInfo=0x14d85f90 {error=Invalid Credentials, GTLStructuredError=GTLErrorObject 0x14d85ba0: {message:"Invalid Credentials" code:401 data:[1]}, NSLocalizedFailureReason=(Invalid Credentials)}
I written the following code in ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = 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;
// 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
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
[signIn trySilentAuthentication];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)refreshInterfaceBasedOnSignIn
{
if ([[GPPSignIn sharedInstance] authentication]) {
// The user is signed in.
NSLog(#"Login");
self.signInButton.hidden = YES;
// Perform other actions here, such as showing a sign-out button
[self getPeopleInfo];
} else {
self.signInButton.hidden = NO;
// Perform other actions here
}
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error
{
NSLog(#"Received error %# and auth object %#",error, auth);
if (error) {
// Do some error handling here.
} else {
[self refreshInterfaceBasedOnSignIn];
}
}
- (void)signOut {
[[GPPSignIn sharedInstance] signOut];
}
- (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.
}
}
-(void)getPeopleInfo
{
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
plusService.retryEnabled = YES;
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
GTLQueryPlus *query =
[GTLQueryPlus queryForPeopleListWithUserId:#"me"
collection:kGTLPlusCollectionVisible];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusPeopleFeed *peopleFeed,
NSError *error) {
if (error) {
GTMLoggerError(#"Error: %#", error);
} else {
// Get an array of people from GTLPlusPeopleFeed
NSArray* peopleList = [peopleFeed.items mutableCopy];
NSLog(#"peopleList:%#", peopleList);
}
}];
}
Call the following method, after login success, for me, i am getting friends list using below method
-(void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
plusService.retryEnabled = YES;
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
GTLQueryPlus *query =
[GTLQueryPlus queryForPeopleListWithUserId:#"me"
collection:kGTLPlusCollectionVisible];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusPeopleFeed *peopleFeed,
NSError *error) {
if (error) {
GTMLoggerError(#"Error: %#", error);
} else {
// Get an array of people from GTLPlusPeopleFeed
NSArray* peopleList = peopleFeed.items;
NSLog(#"peopleList %# ",peopleList);
}
}];
}
As per my experience, Google+ SDK is not having any method fetching the friend list currently.
It's suggested to use Google Contacts API for fetching contacts. It may happen that contacts fetched from this API are not active on Google+. So it's mixed list.
So, Wait for the updates from Google.
We have a way to get google plus visible friends information. Please take a look on description and if it will be not clear enough for you, then I will provide more description.
GTMOAuth2Authentication *auth;
/*That you will get when you login by your google plus account. So I am considering that you already have it.*/
NSMutableArray *arrFriends = [NSMutableArray new];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://www.googleapis.com/plus/v1/people/%#/people/visible?orderBy=alphabetical&access_token=%#",#"your_user_id",auth.accessToken]];
/*When you login via Google plus and fetch your profile information, you will get your user id.*/
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
[request startSynchronous];
if(LOGS_ON) NSLog(#"GooglePlusConnect-->getchGooglePlusFriends-->responseString = %#",request.responseString);
});
Plaease let me know if it is not clear enough for you, then i will provide some more description.
Hi I was also facing same error but it got resolved. The problem is in setting scope.
set the scope as #define kGTLAuthScopePlusLogin #"https://www.googleapis.com/auth/plus.login"
- (void)viewDidLoad
{
[super viewDidLoad];
GPPSignIn *signInG = [GPPSignIn sharedInstance];
signInG.shouldFetchGooglePlusUser = YES;
signInG.shouldFetchGoogleUserEmail = YES;
signInG.clientID = kClientId;
signInG.scopes = # [kGTLAuthScopePlusLogin];
signInG.delegate = self;
[signInG trySilentAuthentication];
}
It will fetch friends details like name, image url but not Email address. For fetching Email address try to use Contact API. iOS has NSXMLParser, the contact api code is given in JS, java, net u could use that and fetch the details.
Hi i was also facing the same problem. This problem Occurring Because of scope.
In Your code You have override the scope.
signIn.scopes = #[ kGTLAuthScopePlusLogin];
With
signIn.scopes = #[ #"profile" ]; // "profile" scope
So, You have to change Your scope By Simple
signIn.scopes = #[ kGTLAuthScopePlusLogin];
Or
signIn.scopes = #[ kGTLAuthScopePlusLogin,#"profile"];
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
plusService.retryEnabled = YES;
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
GTLQueryPlus *query =
[GTLQueryPlus queryForPeopleListWithUserId:#"me"
collection:kGTLPlusCollectionVisible];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusPeopleFeed *peopleFeed,
NSError *error) {
if (error) {
GTMLoggerError(#"Error: %#", error);
} else {
// Get an array of people from GTLPlusPeopleFeed
NSArray* peopleList = peopleFeed.items;
NSLog(#"peopleList %# ",peopleList.description);
for (NSArray *dict in peopleFeed.items) {
NSString *strID=(NSString*)((GTLPlusPerson*)dict).identifier;
NSLog(#"strID %#",strID);
}
}
}];