找到你要的答案

Q:iOS Google Plus sharing with custom GUI

Q:iOS谷歌加自定义GUI共享

I have a question about Google Plus iOS SDK. Is there any way to share a photo and/or message without having to use GPPShareBuilder? I need to make a custom interface to do that and can't find any function or solution to make a simple sharing interface.

Ok. I've enabled Google Plus domains API in developers console. And trying to upload photo via Media:insert. Here is a code:

NSError *error;
NSDictionary *body = @{ @"mediaURL" : photoURL.description };
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:body options:NSJSONWritingPrettyPrinted error:&error];

NSURL *apiURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.googleapis.com/upload/plusDomains/v1/people/me/media/cloud?access_token=%@", [self accessToken]]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:apiURL];
request.HTTPMethod = @"POST";
request.HTTPBody = jsonData;
[request addValue:@"image/JPG" forHTTPHeaderField:@"Content-Type"];
NSOperationQueue *queue= [NSOperationQueue mainQueue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
    NSString *responseString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    NSLog(@"%@", responseString);
}];

And all the time I getting next response:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Forbidden"
   }
  ],
  "code": 403,
  "message": "Forbidden"
 }
}

What is wrong in my code?

我有一个问题关于谷歌Plus的iOS SDK。有什么办法可以分享照片和/或信息,而无需使用GPPShareBuilder?我需要做一个自定义的接口来做这一点,找不到任何功能或解决方案,使一个简单的共享接口。

好啊.我已经启用谷歌加域API在开发控制台。并试图上传照片通过媒体:插入。这里是一个代码:

NSError *error;
NSDictionary *body = @{ @"mediaURL" : photoURL.description };
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:body options:NSJSONWritingPrettyPrinted error:&error];

NSURL *apiURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.googleapis.com/upload/plusDomains/v1/people/me/media/cloud?access_token=%@", [self accessToken]]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:apiURL];
request.HTTPMethod = @"POST";
request.HTTPBody = jsonData;
[request addValue:@"image/JPG" forHTTPHeaderField:@"Content-Type"];
NSOperationQueue *queue= [NSOperationQueue mainQueue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
    NSString *responseString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    NSLog(@"%@", responseString);
}];

和所有的时间,我得到下一个响应:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Forbidden"
   }
  ],
  "code": 403,
  "message": "Forbidden"
 }
}

我的代码怎么了?

answer1: 回答1:

Sure, Google provides a share endpoint at https://plus.google.com/share. This endpoint takes in two parameters: url for your image, and hl for your language code.

You can adjust the metadata that appears when posting your image to Google+ with OpenGraph tags (such as og:title) to the webpage hosting your image.

More about OpenGraph tags can be found in this question: Google+ share url: what parameters does it use?

当然,谷歌提供了一个共享的端点在https://plus.google.com/share。这个端点需要两个参数:URL,你的形象,你的语言代码和HL。

你可以调整你的形象出现时,在谷歌+ OpenGraph标签的元数据(如OG:标题)托管你的图像的网页。

更多关于OpenGraph标签可以在这个问题上发现:谷歌+分享网址:什么参数呢?

ios  objective-c  sdk  google-plus