Objective c react native和设置gmail api

Objective c react native和设置gmail api,objective-c,react-native,gmail-api,Objective C,React Native,Gmail Api,我在设置gmail api时遇到问题。谁能告诉我哪里出了问题 说明: Run the following command to download the library using git: git clone --recursive https://github.com/google/google-api-objectivec-client.git 在命令行中,我导航到项目的根目录并运行该命令 Open Xcode and create a new workspace named "Qui

我在设置gmail api时遇到问题。谁能告诉我哪里出了问题

说明:

Run the following command to download the library using git:

git clone --recursive https://github.com/google/google-api-objectivec-client.git
在命令行中,我导航到项目的根目录并运行该命令

Open Xcode and create a new workspace named "Quickstart".

Using File > Add Files to "Quickstart"..., add the following project to the workspace that you cloned in the previous step:
google-api-objectivec-client/Source/GTLCore.xcodeproj
我没有创建新的工作区,只是使用了现有的工作区。我单击了文件>将文件添加到“收件箱”,并添加了
GTLCore.xcodeproj

Create a new iOS > Application > Single View Application project named "QuickstartApp", with the organization "com.example". Set the Language to Objective-C, and when saving the project set the Add to and Group fields to "Quickstart".
因为我已经有一个项目,我没有做这一步

Add the following frameworks and libraries to the project's Build Phases > Link Binary with Libraries section:
GTL.framework (from GTLiOSCore target)
我点击了我的收件箱项目,选择了构建阶段并添加了GTL.framework

Change the following Build Settings:
Add the flag GTL_BUILT_AS_FRAMEWORK=1 to Preprocessor Macros.
我点击了我的收件箱项目,点击了构建设置,搜索了预处理器宏并添加了那行代码

Add the file google-api-objectivec-client/Source/OAuth2/Touch/GTMOAuth2ViewTouch.xib to the project's Supporting Files group.
我选择了inbox测试>支持文件,右键单击将文件添加到收件箱 但是,文件不在其所在的位置

/google-api-objectivec-client/Deps/gtm-oauth2/Source/Touch/GTMOAuth2ViewTouch.xib
将以下文件添加到QuickstartApp组:

google-api-objectivec-client/Source/Services/Gmail/Generated/GTLGmail_Sources.m

google-api-objectivec-client/Source/Services/Gmail/Generated/GTLGmail.h
我右键单击我的收件箱文件夹并选择“
将文件添加到收件箱”
”这两个文件都已添加到我的收件箱文件夹中

现在,请尝试编译,但出现一个错误:找不到“GTLObject.h”文件

该文件位于步骤3中添加的GTLCore.xcodeproj中。每次我添加其中一个文件时,它都会请求另一个文件

步骤4:我创建了自己的文件

gmail.h

#ifndef gmail_h
#define gmail_h
#import <UIKit/UIKit.h>

#import "GTL/GTMOAuth2ViewControllerTouch.h"
#import "GTLGmail.h"

@interface gmail : UIViewController

@property (nonatomic, strong) GTLServiceGmail *service;
@property (nonatomic, strong) UITextView *output;

@end

#endif /* gmail_h */
\ifndef gmail\u h
#定义gmail\u h
#进口
#导入“GTL/GTMOAuth2ViewControllerTouch.h”
#导入“GTLGmail.h”
@界面gmail:UIViewController
@属性(非原子、强)GTLServiceGmail*服务;
@属性(非原子,强)UITextView*输出;
@结束
#endif/*gmail_h*/
复制并粘贴到新文件中 gmail.m

#导入
#导入“gmail.h”
静态NSString*const kKeychainItemName=@“Gmail API”;
静态NSString*const kClientID=@“这是我的密钥”;
@gmail的实现
@综合服务=_服务;
@综合输出=_输出;
//加载视图时,创建必要的子视图,并初始化Gmail API服务。
-(无效)viewDidLoad{
[超级视图下载];
//创建UITextView以显示输出。
self.output=[[UITextView alloc]initWithFrame:self.view.bounds];
self.output.editable=false;
self.output.contentInset=UIEdgeInsetsMake(20.0,0.0,20.0,0.0);
self.output.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.output];
//初始化Gmail API服务并从密钥链加载现有凭据(如果可用)。
self.service=[[GTLServiceGmail alloc]init];
自助授权人=
[GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
客户ID:kClientID
客户机密:无];
}
//当视图出现时,确保Gmail API服务已授权,并执行API调用。
-(无效)视图显示:(BOOL)动画{
if(!self.service.authorizer.canAuthorize){
//尚未授权,通过将登录UI推到UI堆栈上请求授权。
[self-presentViewController:[self-createAuthController]已设置动画:是完成:无];
}否则{
[自取标签];
}
}
//构造一个查询并从用户的gmail中获取标签列表。显示
//UITextView中的标签名称
-(void)获取标签{
self.output.text=@“获取标签…”;
GTLQueryMail*查询=[GTLQueryMail queryForUsersLabelsList];
[自助服务执行:查询]
代表:赛尔夫
didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
}
-(作废)显示结果票证:(GTL服务票证*)票证
finishedWithObject:(GTLGmailListLabelsResponse*)labelsResponse
错误:(n错误*)错误{
如果(错误==nil){
NSMutableString*labelString=[[NSMutableString alloc]init];
如果(labelsResponse.labels.count>0){
[labelString appendString:@“标签:\n”];
for(labelResponse.labels中的GTLGmailLabel*标签){
[标签字符串格式:@“%@\n”,label.name];
}
}否则{
[labelString appendString:@“未找到标签”。];
}
self.output.text=标签字符串;
}否则{
[自显示警报:@“错误”消息:Error.localizedDescription];
}
}
//创建用于授权访问Gmail API的身份验证控制器。
-(GTMOAuth2ViewControllerTouch*)createAuthController{
GTMOAuth2ViewControllerTouch*authController;
NSArray*作用域=[NSArray arrayWithObjects:KGTLAuthScopegMail只读,无];
authController=[[GTMOAuth2ViewControllerTouch alloc]
initWithScope:[作用域组件通过字符串连接:@“”]
客户ID:kClientID
客户秘密:零
keychainItemName:kKeychainItemName
代表:赛尔夫
finishedSelector:@选择器(viewController:finishedWithAuth:错误:);
返回控制器;
}
//处理授权过程的完成,并更新Gmail API
//用新的证书。
-(无效)视图控制器:(GTMOAuth2ViewControllerTouch*)视图控制器
使用Auth:(GTMOAuth2Authentication*)authResult完成验证
错误:(n错误*)错误{
如果(错误!=nil){
[自显示警报:@“身份验证错误”消息:Error.localizedDescription];
self.service.authorizer=nil;
}
否则{
self.service.authorizer=authResult;
[自我解除视图控制器激活:是完成:无];
}
}
//用于显示警报的帮助程序
-(无效)showAlert:(NSString*)标题消息:(NSString*)消息{
UIAlertView*警报;
alert=[[UIAlertView alloc]initWithTitle:title
信息:信息
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报显示];
}
@结束

文档中指出,“静态库目标还创建了一个包含库头的文件夹,以拖动到目标中
#import <Foundation/Foundation.h>

#import "gmail.h"

static NSString *const kKeychainItemName = @"Gmail API";
static NSString *const kClientID = @"this is my key";

@implementation gmail

@synthesize service = _service;
@synthesize output = _output;

// When the view loads, create necessary subviews, and initialize the Gmail API service.
- (void)viewDidLoad {
  [super viewDidLoad];

  // Create a UITextView to display output.
  self.output = [[UITextView alloc] initWithFrame:self.view.bounds];
  self.output.editable = false;
  self.output.contentInset = UIEdgeInsetsMake(20.0, 0.0, 20.0, 0.0);
  self.output.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  [self.view addSubview:self.output];

  // Initialize the Gmail API service & load existing credentials from the keychain if available.
  self.service = [[GTLServiceGmail alloc] init];
  self.service.authorizer =
  [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
                                                        clientID:kClientID
                                                    clientSecret:nil];
}

// When the view appears, ensure that the Gmail API service is authorized, and perform API calls.
- (void)viewDidAppear:(BOOL)animated {
  if (!self.service.authorizer.canAuthorize) {
    // Not yet authorized, request authorization by pushing the login UI onto the UI stack.
    [self presentViewController:[self createAuthController] animated:YES completion:nil];

  } else {
    [self fetchLabels];
  }
}

// Construct a query and get a list of labels from the user's gmail. Display the
// label name in the UITextView
- (void)fetchLabels {
  self.output.text = @"Getting labels...";
  GTLQueryGmail *query = [GTLQueryGmail queryForUsersLabelsList];
  [self.service executeQuery:query
                    delegate:self
           didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
}

- (void)displayResultWithTicket:(GTLServiceTicket *)ticket
             finishedWithObject:(GTLGmailListLabelsResponse *)labelsResponse
                          error:(NSError *)error {
  if (error == nil) {
    NSMutableString *labelString = [[NSMutableString alloc] init];
    if (labelsResponse.labels.count > 0) {
      [labelString appendString:@"Labels:\n"];
      for (GTLGmailLabel *label in labelsResponse.labels) {
        [labelString appendFormat:@"%@\n", label.name];
      }
    } else {
      [labelString appendString:@"No labels found."];
    }
    self.output.text = labelString;
  } else {
    [self showAlert:@"Error" message:error.localizedDescription];
  }
}


// Creates the auth controller for authorizing access to Gmail API.
- (GTMOAuth2ViewControllerTouch *)createAuthController {
  GTMOAuth2ViewControllerTouch *authController;
  NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeGmailReadonly, nil];
  authController = [[GTMOAuth2ViewControllerTouch alloc]
                    initWithScope:[scopes componentsJoinedByString:@" "]
                    clientID:kClientID
                    clientSecret:nil
                    keychainItemName:kKeychainItemName
                    delegate:self
                    finishedSelector:@selector(viewController:finishedWithAuth:error:)];
  return authController;
}

// Handle completion of the authorization process, and update the Gmail API
// with the new credentials.
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
      finishedWithAuth:(GTMOAuth2Authentication *)authResult
                 error:(NSError *)error {
  if (error != nil) {
    [self showAlert:@"Authentication Error" message:error.localizedDescription];
    self.service.authorizer = nil;
  }
  else {
    self.service.authorizer = authResult;
    [self dismissViewControllerAnimated:YES completion:nil];
  }
}

// Helper for showing an alert
- (void)showAlert:(NSString *)title message:(NSString *)message {
  UIAlertView *alert;
  alert = [[UIAlertView alloc] initWithTitle:title
                                     message:message
                                    delegate:nil
                           cancelButtonTitle:@"OK"
                           otherButtonTitles:nil];
  [alert show];
}

@end