如何使用google-plus-ios-sdk-1.7.1 sdk登录google-plus?
问题描述:
我正在开发使用Google Plus的iPhone应用程序。如何使用google-plus-ios-sdk-1.7.1 sdk登录google-plus?
当我尝试登录时,出现401错误。
我用google-plus-ios-sdk-1.7.1 sdk。
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[GPPSignIn sharedInstance].clientID = kClientID;
// Read Google+ deep-link data.
[GPPDeepLink setDelegate:self];
[GPPDeepLink readDeepLinkAfterInstall];
return YES;
}
在shareviewcontroller
:
-(void)viewDidLoad
{
[super viewDidLoad];
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.scopes = @[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[[GPPSignIn sharedInstance] trySilentAuthentication];
_shareConfiguration = [ShareConfiguration sharedInstance];
_shareConfiguration.useNativeSharebox = YES;
//_shareConfiguration.deepLinkEnabled = YES;
_shareConfiguration.mediaAttachmentEnabled = YES;
}
-(void)btnGoogleShare_Action
{
if ([GPPSignIn sharedInstance].authentication) {
id<GPPShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
[(id<GPPNativeShareBuilder>)shareBuilder attachImage:self.imgView.image];
[(id<GPPNativeShareBuilder>)shareBuilder setTitle:self.dict[@"title"] description:self.dict[@"comment"] thumbnailURL:nil];
[shareBuilder open];
}
else
{
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
GPPSignInButton *sign = [[GPPSignInButton alloc] init];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
appDelegate.alert = [[UIAlertView alloc] initWithTitle:@"Sign to Google +" message:@"After login to Google+, Please retry again." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Cancel", nil];
[appDelegate.alert setValue:sign forKey:@"accessoryView"]; //works only in iOS7
} else {
appDelegate.alert = [[UIAlertView alloc] initWithTitle:@"Sign to Google +" message:@"After login to Google+, Please retry again.\n\n\n" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Cancel", nil];
sign.frame = CGRectMake(70, 85, 100, 40);
[appDelegate.alert addSubview:sign];
}
[GPPSignInButton class];
[appDelegate.alert show];
}
}
下面是截图,谁能帮助我?
答
正如在评论中提到的,第一个问题已经讨论here。
有关文本和媒体同时发布的第二个问题在GPPNativeShareBuilder Protocol Reference的API文档中提及。根据此文档,您不能使用attachImage
和setTitle
函数。功能setPrefillText
可以解决您的问题。
尝试检查此答案:http://*.com/questions/18677244/error-invalid-client-no-application-name – 2014-10-07 12:32:13
我已成功登录,但我有另一个错误。“你不能同时附加链接和媒体到帖子。“,我怎样才能同时分享图片和文字? – 2014-10-07 14:13:34
根据文档https://developers.google.com/+/mobile/ios/api/protocol_g_p_p_native_share_builder-p#a9fabcb8ede280d903e1270f58e9928af,不能使用'attachImage'和'setTitle'函数。可能是'setPrefillText'将解决你的问题。 – 2014-10-07 14:45:45