- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在开发一个需要在 Swift 中使用 Google Calendar API 的应用程序。不幸的是,该项目的进展处于停滞状态,因为我无法确定需要如何继续才能克服标题中显示的错误。它在执行谷歌登录功能后出现。绕过 firebase 客户端 ID,转而使用通过 Google 开发者控制台生成的不同客户端 ID 似乎也无法解决问题。在代码中的多次情况下,我添加了范围值,并根据另一个 stackoverflow 用户的解决方案向范围添加了“https://www.googleapis.com/auth/userinfo.profile ”,但这些都没有解决我的问题。我确实有一个 Google-Info.plist 文件,该文件已正确配置了反向 ID 和 url 方案,并且还尝试使用该 plist 文件中的客户端 id 来执行该功能,但它似乎仍然没有工作。下面我包含了程序的两个主要部分的代码,其中包括对日历 API 或授权函数的引用。如果您发现任何可能未正确实现的内容,或者我是否错过了使其正常工作的步骤,请告诉我。我的大部分代码都基于此处提供的快速入门代码:https://developers.google.com/google-apps/calendar/quickstart/ios?ver=swift
只需稍作修改即可额外实现 Firebase。注意:登录似乎确实有效,并且成功地将数据传输到 Firebase,但一旦调用 Google 日历,它就不允许进一步的进展。除了我在下面提供的内容之外,还有一个单独的 View Controller ,其中包含谷歌登录按钮,但我不相信我遇到的问题存在于该类中,因此将其排除在外。
APPDELEGATE
import UIKit
import Firebase
import GoogleSignIn
import FirebaseDatabase
import GoogleAPIClientForREST
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var scopes = [kGTLRAuthScopeCalendarReadonly, "https://www.googleapis.com/auth/userinfo.profile"]
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().scopes = scopes
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UINavigationController(rootViewController: ViewController())
window?.makeKeyAndVisible()
return true
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let err = error {
print("Failed to log into Google: ", err)
return
}
print("Successfully logged into Google", user)
//Allows information to be stored in Firebase Database
let ref = Database.database().reference(fromURL: "https://tesseractscheduler.firebaseio.com/")
guard let idToken = user.authentication.idToken else { return }
guard let accessToken = user.authentication.accessToken else { return }
LoginController().service.authorizer = user.authentication.fetcherAuthorizer()
let credentials = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: accessToken)
Auth.auth().signIn(with: credentials, completion: { (user, error) in
if let err = error {
print("Failed to create a Firebase User with Google account: ", err)
return
}
//successfully authenticated user
guard let uid = user?.uid else { return }
print("Successfully logged into Firebase with Google", uid)
//Creates database entry with users unique identifier, username, and email. "null" provided to prevent errors.
ref.updateChildValues(["UID": uid, "username": user?.displayName ?? "null", "Email": user?.email ?? "null"])
//Pushes to next screen if login has occurred.
if GIDSignIn.sharedInstance().hasAuthInKeychain(){
//GIDSignIn.sharedInstance().clientID = "197204473417-56pqo0dhn8v2nf5v64aj7o64ui414rv7.apps.googleusercontent.com"
self.window?.rootViewController = UINavigationController(rootViewController: LoginController())
}
LoginController().fetchEvents()
})
}
func application(_ application: UIApplication, open url: URL, options:
[UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
GIDSignIn.sharedInstance().handle(url,
sourceApplication: options[
UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation : options[UIApplicationOpenURLOptionsKey.annotation])
return true
}
LOGINCONTROLLER
import UIKit
import GoogleSignIn
import Firebase
import GoogleAPIClientForREST
class LoginController: UIViewController {
let service = GTLRCalendarService()
let output = UITextView()
let appDelegate = (UIApplication.shared.delegate as? AppDelegate)
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Logout", style: .plain, target: self, action: #selector(didTapSignOut))
view.backgroundColor = UIColor(red: 61/255, green: 91/255, blue: 151/255, alpha: 1)
output.frame = view.bounds
output.isEditable = false
output.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
output.autoresizingMask = [.flexibleHeight, .flexibleWidth]
output.isHidden = true
view.addSubview(output);
}
func fetchEvents() {
let query = GTLRCalendarQuery_EventsList.query(withCalendarId: "primary")
query.maxResults = 10
query.timeMin = GTLRDateTime(date: Date())
query.singleEvents = true
query.orderBy = kGTLRCalendarOrderByStartTime
service.executeQuery(
query,
delegate: self,
didFinish: #selector(displayResultWithTicket(ticket:finishedWithObject:error:)))
}
@objc func displayResultWithTicket(
ticket: GTLRServiceTicket,
finishedWithObject response : GTLRCalendar_Events,
error : NSError?) {
if let error = error {
showAlert(title: "Error", message: error.localizedDescription)
return
}
var outputText = ""
if let events = response.items, !events.isEmpty {
for event in events {
let start = event.start!.dateTime ?? event.start!.date!
let startString = DateFormatter.localizedString(
from: start.date,
dateStyle: .short,
timeStyle: .short)
outputText += "\(startString) - \(event.summary!)\n"
}
} else {
outputText = "No upcoming events found."
}
output.text = outputText
}
private func presentViewController(alert: UIAlertController, animated flag: Bool, completion: (() -> Void)?) -> Void {
UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: flag, completion: completion)
}
//Shows an error alert with a specified output from the log.
func showAlert(title : String, message: String) {
let alert = UIAlertController(
title: title,
message: message,
preferredStyle: UIAlertControllerStyle.alert
)
let ok = UIAlertAction(
title: "OK",
style: UIAlertActionStyle.default,
handler: nil
)
alert.addAction(ok)
presentViewController(alert: alert, animated: true, completion: nil)
}
//Communicated to navigation button to perform logout function.
@objc func didTapSignOut(_ sender: AnyObject) {
GIDSignIn.sharedInstance().signOut()
print("Successfully logged out of Google.")
showAlert(title: "Log Off", message: "Logout Successful!")
appDelegate?.window?.rootViewController = UINavigationController(rootViewController: ViewController())
}
// Do any additional setup after loading the view.
}
如果您还需要提供任何其他信息以帮助识别问题,请告诉我。我进行了广泛的搜索,但无法找到针对我的特定问题的解决方案。如果这是一个愚蠢的问题,我深表歉意:我对 API 的合并还很陌生。
最佳答案
我还不能确定是否有更有效的解决方法,但目前我已经能够通过删除对 Firebase 的所有引用的代码并忽略其实现来避免此错误。我使用 Firebase 验证 Google 登录的方式导致了此错误的发生。删除 Firebase 后,这不再是问题。 El Tomato 的问题促使我尝试这种方法,到目前为止我至少能够取得进展。如果我稍后有时间参与该项目,我可能会回来看看是否可以在不发生错误的情况下实现它们,但目前这是一个不重要的功能。
关于ios - 在 Swift 中使用 Google Calendar API 时收到错误 "Daily Limit For Unauthenticated Use Exceeded",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48880324/
好吧,我对我的页面发生的事情有点困惑。我在底部有页码, table 上摆满了 23 种不同的元素。 每个页面应一次显示 5 个项目。我显示的页面发送了一个带有 pagenumber = 不管怎样的 g
几周前我开始学习 Ada。我知道 limited 在某些情况下声明了一个有限类型,不允许复制对象 来自 Ada Reference Manual 2012 7.5 1/2 A limited type
我想按 DESC 选择日期并限制为最后 3 个,然后我需要基本上翻转最后 3 个结果,以便它们按 ASC 排序 任何帮助将不胜感激,我正在使用 postgresql 最佳答案 SELECT * FRO
SELECT * FROM mm_tfs WHERE product_slug LIKE '%football%' AND schoolid = '8' AND category_id ='2
SELECT * FROM mm_tfs WHERE product_slug LIKE '%football%' AND schoolid = '8' AND category_id ='2
我正在尝试访问按“日期”键排序的表中恒定数量的最新文档。请注意,不幸的是,日期是被实现的(不是由我......),使得该值设置为字符串,例如“2014-01-14”,或者有时“2014-01-14 2
我目前正在使用具有限制 cpu、限制内存以及保留 cpu 和内存的 Docker Swarm。 完成测试后,我想删除这些配置。我找不到任何有关如何删除这些的文章。 是否有办法通过更新来删除这些设置而不
我目前正在使用具有限制 cpu、限制内存以及保留 cpu 和内存的 Docker Swarm。 完成测试后,我想删除这些配置。我找不到任何有关如何删除这些的文章。 是否有办法通过更新来删除这些设置而不
我必须对我的数据应用分页。我通过复杂的连接查询获取数据,没有任何子查询,只有简单的连接。 假设这个查询[这是一个非常简单的查询,我有一个比这个复杂的查询] SELECT states.state
我经常制作条形图,并将条形图的值额外包含为注释 (geom_text)。通常,我更喜欢这些值右对齐(与将标签放在条形顶部相反)。在绘制多面条形图时,我将这些值放在每个组中的最大值(我之前计算过)加上我
delivery-limit 和 x-delivery-limit 有什么区别? 当我将 x-delivery-limit 设置为 RabbitMQ 队列参数时,我可以看到它限制了我的消息重新排队尝试
delivery-limit 和 x-delivery-limit 有什么区别? 当我将 x-delivery-limit 设置为 RabbitMQ 队列参数时,我可以看到它限制了我的消息重新排队尝试
我正在使用 PostgreSQL 9.3。这应该在具有 100,000 多行的任何表上重现。 EXPLAIN ANALYZE 显示使用 LIMIT 2 扫描了更多行,但我不明白为什么。 限制 1: E
我正在尝试找出是否可以在 PHP 中全局设置和取消设置 MySQL 结果的默认限制。 一些可能看起来像的伪代码: $pdo->prepare('SELECT * FROM example'); $pd
我有下面的代码片段表 在这里我必须对投票前 3 个值求和。 假设 product_id 3030 vote 列的总和为 8.1 和 3671 总和 是 5.2 在这里,我必须获得前 3 个 produ
我正在使用全文搜索来提取行。 我根据分数 (ORDER BY SCORE) 对行进行排序,然后在前 20 行 (LIMIT 20) 中,我想对结果集进行兰德 (RAND)。 因此,对于任何特定的搜索词
帮助创建搜索条件 SELECT * FROM mlt_adr_city WHERE name LIKE "Text%" AND region_id = 59 AND id <> 0 IF (name
MySQL 查询示例: SELECT message_id, message_text FROM messages LIMIT 0 , 30 我得到的这个提示是错误的: HIN
我注意到如果我将查询限制为 1 个而不是 5 个,速度会急剧下降。 SELECT he. * FROM homematic_events he WHERE he.homematic_devices_i
我需要从我的表中获取最后一个 ID,以便我可以在另一个函数中使用它我在我的存储库中创建了这个函数,但我没有工作,它显示了一个错误: [Syntax Error] line 0, col 60: Err
我是一名优秀的程序员,十分优秀!