我想在我的应用中添加google-plus属性的分享。 我在Google Web控制台上注册了客户端应用程序并获得了客户端ID。
在我的viewDidLoad函数中:
- (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];
}
然后在我的onButtonCLick函数中:
- (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];
}
但是我收到了消息:
[lvl=3] -[GPPNativeShareBuilderImpl open] User must be signed in to use the native share box.
我从App Store下载了google + app并登录。但每次收到此邮件时都无法在Google +上分享任何内容。
有什么建议吗?
答案 0 :(得分:7)
首先从模拟器中删除您的应用程序然后关闭XCode并通过更改以下代码重新打开并再次运行您的应用程序:
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = kClientId;
signIn.scopes = @[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[signIn authenticate];
并确保您必须将GooglePlus.bundle
添加到您的应用程序中。