Aynı sorunu iOS uygulamamda da gördüm ve aynı soruyu Can I use Google Drive SDK with sign in information from Google Sign In SDK in iOS da teslim aldım. Eran Marom'un cevabını çizerek Google Sign In kimlik bilgimi, Apps Komut Dosyası Yürütme API'sine başarılı bir şekilde erişebildiğim bir OAuth2 kimlik bilgisine dönüştürebiliyordum.
Swift'de çalıştım. App Delegesi olarak
: viewController yılında
import GTMOAuth2
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
//Create an authorization fetcher, which will be used to pass credentials on to the API request
var myAuth: GTMFetcherAuthorizationProtocol? = nil
// [START didfinishlaunching]
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Initialize sign-in
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
GIDSignIn.sharedInstance().delegate = self
let scopes = "https://www.googleapis.com/auth/drive"
GIDSignIn.sharedInstance().scopes.append(scopes)
return true
}
//....
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
//sets credentials in fetcher
myAuth = user.authentication.fetcherAuthorizer()
//...
} else {
}
//....
:
import UIKit
import GoogleAPIClient
import GTMOAuth2
@objc(ViewController)
class ViewController: UITableViewController, GIDSignInUIDelegate {
private let kClientID = "CLIENT ID"
private let kScriptId = "SCRIPT ID"
private let service = GTLService()
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().uiDelegate = self
//...
}
func toggleAuthUI() {
if (GIDSignIn.sharedInstance().hasAuthInKeychain()){
self.service.authorizer = appDelegate.myAuth
//...
callAppsScript()
} else {
//...
}
@objc func receiveToggleAuthUINotification(notification: NSNotification) {
if (notification.name == "ToggleAuthUINotification") {
self.toggleAuthUI()
if notification.userInfo != nil {
let userInfo:Dictionary<String,String!> =
notification.userInfo as! Dictionary<String,String!>
self.statusText.text = userInfo["statusText"]
}
}
}
func callAppsScript() {
let baseUrl = "https://script.googleapis.com/v1/scripts/\(kScriptId):run"
let url = GTLUtilities.URLWithString(baseUrl, queryParameters: nil)
// Create an execution request object.
var request = GTLObject()
request.setJSONValue("APPS_SCRIPT_FUCTION", forKey: "function")
// Make the API request.
service.fetchObjectByInsertingObject(request,
forURL: url,
delegate: self,
didFinishSelector: "displayResultWithTicket:finishedWithObject:error:")
}
func displayResultWithTicket(ticket: GTLServiceTicket,
finishedWithObject object : GTLObject,
error : NSError?) {
//Display results...
}
http://stackoverflow.com/a/36383136/4024736 bakın – Necreaux
tarihinde eski işareti kaldırıyoruz oldukça etkileyici olmayan - Yeni akışı kullanmak için belgelerini güncellemeden önce akış. Belge sayfasında geri bildirim göndermenizi öneririm: https://developers.google.com/drive/ios/quickstart –