gpt4 book ai didi

objective-c - native react 并设置 gmail api

转载 作者:搜寻专家 更新时间:2023-10-30 20:24:35 25 4
gpt4 key购买 nike

我在设置 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.

我点击了我的收件箱项目,点击了build设置,搜索预处理器宏并添加了那行代码。

Add the file google-api-objectivec-client/Source/OAuth2/Touch/GTMOAuth2ViewTouch.xib to the project's Supporting Files group.

我选择了 inboxTests > supporting files,右键单击 add files to 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'file not found

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

第四步:我创建了自己的文件

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 */

复制并粘贴到一个新文件中gmail.m

#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

最佳答案

文档指出“静态库目标还创建了一个文件夹,其中包含库的 header 以拖入目标的源”。对应的目录只有一个头文件GTLDefines.h,显然没有引用其他需要的头文件,比如GTLObject.h,也没有只包含头文件的文件夹文件。我认为有必要手动添加对将其他所需的头文件(例如 Objects/GTLObject.h)添加到应用程序项目中。

也试着看看这个 link .它在这里声明他将标题从 GTL.proj 导入到他的项目中。其中包括 GTLBase64.hGTLBatchQuery.hGTLBatchResult.h 等文件。没有 header ,他在导入语句中收到错误 “找不到 GTLObject.h 文件。”

关于objective-c - native react 并设置 gmail api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35161822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com