2016-04-06 22 views
1

Bu API'yi kullanan var mı ve bunu anladı mı? Bu üçüncü tarafım, bu kılavuzu aşağıdaki makale izlenerek çalışmaya çalışmaktadırApps Komut Dosyası API'sı hataları ViewController üzerinde

Bu kılavuzun hızlı sürümünü kullanıyorum.

Google Apps Script Guide

Ve hep aynı hataları bana verin.

import UIKit 

class ViewController: UIViewController { 

    private let kKeychainItemName = "Google Apps Script Execution API" 
    private let kClientID = "493692471278-3mf6bo212flgjopl06hrjfeepphe70h4.apps.googleusercontent.com" 
    private let kScriptId = "Mj0RNm2ZtohFurieBLPwnxYAb4Jnnku4P" 
    // If modifying these scopes, delete your previously saved credentials by 
    // resetting the iOS simulator or uninstall the app. 
    private let scopes = ["https://www.googleapis.com/auth/drive"] 

    private let service = GTLService() // error Use of unresolved identifier 'GTLService' 


    let output = UITextView() 

    // When the view loads, create necessary subviews 
    // and initialize the Google Apps Script Execution API service 
    override func viewDidLoad() { 
     super.viewDidLoad() 

     output.frame = view.bounds 
     output.editable = false 
     output.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0) 
     output.autoresizingMask = UIViewAutoresizing.FlexibleHeight | 
      UIViewAutoresizing.FlexibleWidth 
     // error*** Binary operator '|' cannot be applied to two 'UIViewAutoresizing'  operands 


     view.addSubview(output); 
     // Error**Use of unresolved identifier 'GTMOAuth2ViewControllerTouch' 
     if let auth = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(
      kKeychainItemName, 
      clientID: kClientID, 
      clientSecret: nil) { 
       service.authorizer = auth 
     } 

    } 

    // When the view appears, ensure that the Google Apps Script Execution API service is authorized 
    // and perform API calls 
    override func viewDidAppear(animated: Bool) { 
     if let authorizer = service.authorizer, 
      canAuth = authorizer.canAuthorize where canAuth { 
       callAppsScript() 
     } else { 
      presentViewController(
       createAuthController(), 
       animated: true, 
       completion: nil 
      ) 
     } 
    } 

    // Calls an Apps Script function to list the folders in the user's 
    // root Drive folder. 
    func callAppsScript() { 
     output.text = "Getting folders..." 
     let baseUrl = "https://script.googleapis.com/v1/scripts/\(kScriptId):run" 
     let url = GTLUtilities.URLWithString(baseUrl, queryParameters: nil) 
     // error ** Use of unresolved identifier 'GTLUtilities' 
     // Create an execution request object. 
     var request = GTLObject() 
     // Error** Use of unresolved identifier 'GTLObject' 

     request.setJSONValue("getFoldersUnderRoot", forKey: "function") 

     // Make the API request. 
     service.fetchObjectByInsertingObject(request, 
      forURL: url, 
      delegate: self, 
      didFinishSelector: "displayResultWithTicket:finishedWithObject:error:") 
    } 

    // Displays the retrieved folders returned by the Apps Script function. 
    func displayResultWithTicket(ticket: GTLServiceTicket, 
     finishedWithObject object : GTLObject, 
     error : NSError?) { 
      if let error = error { 
       // The API encountered a problem before the script 
       // started executing. 
       showAlert("The API returned the error: ", 
        message: error.localizedDescription) 
       return 
      } 

      if let apiError = object.JSON["error"] as? [String: AnyObject] { 
       // The API executed, but the script returned an error. 

       // Extract the first (and only) set of error details and cast as 
       // a Dictionary. The values of this Dictionary are the script's 
       // 'errorMessage' and 'errorType', and an array of stack trace 
       // elements (which also need to be cast as Dictionaries). 
       let details = apiError["details"] as! [[String: AnyObject]] 
       var errMessage = String(
        format:"Script error message: %@\n", 
        details[0]["errorMessage"] as! String) 

       if let stacktrace = 
        details[0]["scriptStackTraceElements"] as? [[String: AnyObject]] { 
         // There may not be a stacktrace if the script didn't start 
         // executing. 
         for trace in stacktrace { 
          let f = trace["function"] as? String ?? "Unknown" 
          let num = trace["lineNumber"] as? Int ?? -1 
          errMessage += "\t\(f): \(num)\n" 
         } 
       } 

       // Set the output as the compiled error message. 
       output.text = errMessage 
      } else { 
       // The result provided by the API needs to be cast into the 
       // correct type, based upon what types the Apps Script function 
       // returns. Here, the function returns an Apps Script Object with 
       // String keys and values, so must be cast into a Dictionary 
       // (folderSet). 
       let response = object.JSON["response"] as! [String: AnyObject] 
       let folderSet = response["result"] as! [String: AnyObject] 
       if folderSet.count == 0 { 
        output.text = "No folders returned!\n" 
       } else { 
        var folderString = "Folders under your root folder:\n" 
        for (id, folder) in folderSet { 
         folderString += "\t\(folder) (\(id))\n" 
        } 
        output.text = folderString 
       } 
      } 
    } 

    // Creates the auth controller for authorizing access to Google Apps Script Execution API 
    private func createAuthController() -> GTMOAuth2ViewControllerTouch { 
    // Error** Use of undeclared type 'GTLServiceTicket'  let scopeString = " ".join(scopes) // Error* 'join' is unavailable: call the 'joinWithSeparator()' method on the sequence of elements 
     return GTMOAuth2ViewControllerTouch(
      scope: scopeString, 
      clientID: kClientID, 
      clientSecret: nil, 
      keychainItemName: kKeychainItemName, 
      delegate: self, 
      finishedSelector: "viewController:finishedWithAuth:error:" 
     ) 
    } 

    // Handle completion of the authorization process, and update the Google Apps Script Execution API 
    // with the new credentials. 
    func viewController(vc : UIViewController, 
     finishedWithAuth authResult : GTMOAuth2Authentication, error : NSError?) 
    // Error** Use of undeclared type 'GTMOAuth2Authentication' { 

      if let error = error { 
       service.authorizer = nil 
       showAlert("Authentication Error", message: error.localizedDescription) 
       return 
      } 

      service.authorizer = authResult 
      dismissViewControllerAnimated(true, completion: nil) 
    } 

    // Helper for showing an alert 
    func showAlert(title : String, message: String) { 
     let alert = UIAlertView(
      title: title, 
      message: message, 
      delegate: nil, 
      cancelButtonTitle: "OK" 
     ) 
     alert.show() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

} 

Zor google bir rehber yapmak ve xcode güncel sürümü için çalışmıyor olurdu inanmak zor. Hatta kılavuzlarının en sonuncusunun en son Şubat 2016'da güncellendiğini söylüyor.

Geçmişte bu kılavuzu takip eden herhangi birinin şansı olup olmadığını görmek istedim.

Bu google API için başka bir hızlı kılavuz var mı?

Önceden teşekkür ederiz.

+0

Hangi hatalar? Daha fazla bilgi verdiğinizde daha az cevap verir misiniz? – user3069232

+0

Görünüm denetleyicisini kopyalayıp yapıştırmamı söyler ve bana hata verir. Bundan önce adımları attığımı farz edersem, objektif-c'den süratli dönüşüme kadar bir sorun olur muydu? –

cevap

0

1) Başlık dosyalarını almadığınız anlaşılıyor. Bridging-Header.h'ye ihtiyacınız var. Bu adım Quickstart'tan çıkarıldı; Yapmanız gereken adım için Google Drive Hızlı Başlangıç ​​sayfasına bakın. 2) Aşağıdaki satırı yorumlayabilirsiniz, gerekli görünmüyor.

3) Bu değişiklikler derleme sorunlarını düzeltir. Derleme sorunlarını düzelttikten sonra, bir telefonla bağlantı kurup çalıştırılamayacağını buldum. Hızlı Başlangıç ​​kılavuzu, Xcode'un 'Kitaplıklarla Bağlantı İkilisini' kullanarak GTL.framework uygulamasını uygulamanıza bağlamanıza olanak tanır. Bunun yerine Cocoapods (https://cocoapods.org/pods/Google-API-Client) kullanarak yükledim ve daha sonra uygulamamı çalıştırabiliyordum.

İlgili konular