User must be signed in to use the native share box - ios

I want to add share on google-plus property in my application.
I registered client application on google web console and obtained client-id.
In my viewDidLoad function :
- (void)viewDidLoad{
CGRect rect = self.view.bounds;
rect.size.height = rect.size.height - 50;
_postContentUIWV = [[UIWebView alloc] initWithFrame:rect];
[_postContentUIWV loadHTMLString:selectedPostCD.content baseURL:nil];
[self.view addSubview:_postContentUIWV];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
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;
[GPPSignIn sharedInstance].actions = [NSArray arrayWithObjects:
#"http://schemas.google.com/AddActivity",
#"http://schemas.google.com/BuyActivity",
#"http://schemas.google.com/CheckInActivity",
#"http://schemas.google.com/CommentActivity",
#"http://schemas.google.com/CreateActivity",
#"http://schemas.google.com/ListenActivity",
#"http://schemas.google.com/ReserveActivity",
#"http://schemas.google.com/ReviewActivity",
nil];
// 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];
}
Then in my onButtonCLick function:
- (void) googlePlusShareTapped {
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
[shareBuilder setURLToShare:[NSURL URLWithString:#"https://www.shinnxstudios.com"]];
[shareBuilder setPrefillText:#"This is an awesome G+ Sample to share"];
// [shareBuilder setTitle:#"Title" description:#"Descp" thumbnailURL:[NSURL URLWithString:#"https://www.fbo.com/imageurl"]];
[shareBuilder open];
}
However I get the message:
[lvl=3] -[GPPNativeShareBuilderImpl open] User must be signed in to use the native share box.
I downloaded google+ app from App Store and signed in. But every time I get this message and cannot share anything on google+.
Any suggestions?

First remove your application from simulator then close XCode and reopen and run your app again by changing with following code:
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = kClientId;
signIn.scopes = #[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[signIn authenticate];
And also make sure that you have to added GooglePlus.bundle in to your application.

Related

how to get UserID from Google plus Oauth2.0 for IOS

I used Google Developers Documentation but I can't take UserID
this is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.0f/255.0f green:102.0f/255.0f blue:204.0f/255.0f alpha:100.0];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
signIn = [GPPSignIn sharedInstance];
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientId;
[signIn setScopes:[NSArray arrayWithObject: #"https://www.googleapis.com/auth/plus.me"]];
// Uncomment to get the user's email
signIn.shouldFetchGoogleUserEmail = YES;
// Uncomment to get the user's ID
signIn.shouldFetchGoogleUserID = YES;
signIn.delegate = self;
Gplusbtn = [[GPPSignInButton alloc] init];
Gplusbtn.frame = CGRectMake([simod CG:10], [simod CG:125], [simod CG:300], [simod CG:30]);
Gplusbtn.style=kGPPSignInButtonStyleWide;
Gplusbtn.enabled = YES;
[self.view addSubview:Gplusbtn];
}
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error) {
_signInAuthStatus.text =
[NSString stringWithFormat:#"Status: Authentication error: %#", error];
return;
}
NSLog(#"ID:%#", signIn.userID);
}
NSLog show ID:(null)
So where code has a problem, how to fix it?
You just need to use
[GPPSignIn sharedInstance]
like this:
NSString * gpUserID = [GPPSignIn sharedInstance].userID;

Google Plus login - provide user email redirect to browser/Google Plus app

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];
}

Social Logout Google Plus Issue in iOS

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

Google Plus Sign in From other UIViewController

when i signin in the Main ViewController in my Case ViewController.m every think works fine
with same code i sign in on other UIViewController login.m
when i close the app and run again trysilentauthentication will return false always
its lookalike nothing saved
i use this code to sign in login.m :
signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.clientID = kClientId;
signIn.scopes = #[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[signIn authenticate];
and i check in ViewController.m :
if ([signIn trySilentAuthentication]) {
NSLog(#"trySilentAuthentication Return True");
}else {
NSLog(#"trySilentAuthentication Return False");
}
and i sign out in login.m using :
- (IBAction)signOut:(id)sender {
[self ClearUserData];
[[GPPSignIn sharedInstance] signOut];
[self refreshInterfaceBasedOnSignIn];
}
is it something With Delegate ?

Google+ stop sharing in ios

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];
}

Resources