用于服务器+ Xcode 8.1的Swift + Vapor框架
我正在尝试阅读Firebase实时数据库向我的数据库发出HTTP请求,但我得到了许可被拒绝.
以下是这些步骤:
1.使用从"console.developers.google.com"下载的密钥创建JWT签名
2.将POST请求发送到OAuth2服务器并获取访问令牌
3.将GET请求发送到firebase数据库,并从中接收访问令牌OAuth2服务器.
我得到"权限被拒绝",HTTP/1.1 403禁止
// the header of the JSON Web Token (first part of the JWT)
let headerJWT = ["alg":"RS256","typ":"JWT"]
// the claim set of the JSON Web Token
let jwtClaimSet =
["iss":"firebase-adminsdk-kxx5h@fir-30c9e.iam.gserviceaccount.com",
"scope":"https://www.googleapis.com/auth/firebase.database", //is this the correct API to access firebase database?
"aud":"https://www.googleapis.com/oauth2/v4/token",
"exp": expDate,
"iat": iatDate]
drop.get("access") { request in
var accesstoken = "ya29.ElqhA-....XXXX"
let responseFirebase = try drop.client.get("https://fir- 30c9e.firebaseio.com/data/Users.json",
headers: ["Authorization":"Bearer \(accesstoken)"],
query: [:])
print("FirebaseResponse_is \(responseFirebase)")
return "success" …Run Code Online (Sandbox Code Playgroud) 我尝试使用 Vapor 1.5 和 Firebase 旧协议向 Firebase 通知 API 发出 POST 请求,但收到失败响应。
响应为 JSON(node: Node.Node.object(["multicast_id": Node.Node.number(5936281277445399934), "failure": Node.Node.number(0), "canonical_ids": Node.Node.number(0) ), "结果": Node.Node.array([Node.Node.object(["message_id": Node.Node.string("0:1527074314969790%c7ade8b9f9fd7ecd")])]), "成功": Node.Node 。1号)]))
编辑 通过 POSTMan 发出请求失败,并出现错误“请求缺少身份验证密钥(FCM 令牌)”。
class FirebaseRequester {
let fcmLegacyServerKey = "AIzaSyDSuXXXXXXkCafTQay5_r8j3snvVos"
func sendNotification(payLoad: JSON) throws -> Response {
var response: Response?
do {
let responseFCM = try drop.client.post("https://fcm.googleapis.com/fcm/send",
headers: ["Content-Type":"application/json","Authorization": "key\(fcmLegacyServerKey)"],
query: [:],
body: payLoad.makeBody())
response = responseFCM
}catch let error {
let message = error.localizedDescription
logErr.prints(message: message)
throw Abort.custom(status: .badRequest, message: …Run Code Online (Sandbox Code Playgroud) 我已在https://developer.yahoo.com/apps/BY4faaaa/注册了我的应用程序
我如何授予雅虎邮件阅读范围?由于仪表板中未显示范围,
如何启用范围?mail-r
在此屏幕截图中,是雅虎的[电子邮件范围],但我看不到授予读取经过身份验证的用户电子邮件的权限的范围(https://developer.yahoo.com/oauth2/guide/yahoo_scopes/)
如何获取当前页面的url?
用途:通过Gmail客户端登录
(async () => {
const browser = await puppeteer.launch({headless:false, slowMo:50});
const page = await browser.newPage();
await page.goto('https://my.gumtree.com/login', {waitUntil: 'networkidle2'});
//click on Google Sign In button
const myButton = await page.$('#google-sign-in-button');
myButton.click();
//wait for the pop up window to load
const nav1 = new Promise(res => browser.on('targetcreated', res))
await nav1
const pages = await browser.pages();
const secondPage = pages[2];
await secondPage.focus('input[type=email]')
await secondPage.keyboard.type('someValidEmail@gmail.com')
customButton = await secondPage.$('span.VfPpkd-vQzf8d');
customButton.click()
//Everything works as expected until here
await page.waitForNavigation()
Run Code Online (Sandbox Code Playgroud)
** 如何获取当前页面的url?应位于索引 3 …
在UIViewController中,我有几个文本字段,一个按钮位于UIViewController的底部.对于按钮,我设置了一个常量为0的底部约束.然后我从底部约束到UIViewController创建了一个出口.
当我运行我的代码时,按钮不会向上移动.我已经看到了关于stackoverflow的建议,我应该添加UIScrollView,但这意味着,我必须删除UIViewController上的所有对象,放置UIScrollView,然后再次将我的对象放在UIVIewController上.
@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
// When tapping outside of the keyboard, close the keyboard down
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
// Stop Editing on Return Key Tap. textField parameter refers to any textfield within the view
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
// when keyboard is about to show assign the height of the keyboard to bottomConstraint.constant of our button so that it will move up
func keyboardWillShow(notification: …Run Code Online (Sandbox Code Playgroud) 为什么我的浏览器无法加载 Chrome?我收到错误:
该消息是无法启动浏览器进程!生成 /Applications/GoogleChrome.app ENOENT 故障排除: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
节点版本 v13.12.0
const browser = await puppeteer.launch({executablePath:'/Applications/Google\Chrome.app'});
const page = await browser.newPage();
await page.goto('https://my.gumtree.com/login', {waitUntil: 'networkidle2'});
const myButton = await page.$('#google-sign-in-button');
myButton.click();
Run Code Online (Sandbox Code Playgroud)
当我尝试运行时node app.js,出现错误:
消息是无法启动浏览器进程!spawn /Users/iliebogdanbarbulescu/Downloads/firstProject/node_modules/chromium/lib/chromium/chrome-mac/Chromium.app
EACCES
我做了什么,
我检查了文件夹,/Users/iliebogdanbarbulescu/Downloads/firstProject/node_modules/chromium/lib/chromium/chrome-mac/Chromium.app但文件没有压缩。它可以运行。
注意:
如果我尝试在没有路径的情况下执行,它可以工作,但我想使用 Chrome 或 Chromium 打开一个新页面。
const browser = await puppeteer.launch({headless:false'});
const express = require('express');
const puppeteer = require('puppeteer');
const app = express();
(async () => {
const browser = await puppeteer.launch({headless:false, executablePath:'/Users/iliebogdanbarbulescu/Downloads/firstProject/node_modules/chromium/lib/chromium/chrome-mac/Chromium.app'});
const page = await browser.newPage();
await page.goto('https://google.com', {waitUntil: 'networkidle2'});
})().catch((error) =>{
console.error("the message is " + error.message);
});
app.listen(3000, function (){
console.log('server started');
})
Run Code Online (Sandbox Code Playgroud)
我正在开发一个用于清洁服务的应用程序。在此应用程序中,员工(清洁工)可以读取由多个客户(用户)完成的作业(预订)列表。
所有清洁工都可以在“用户”节点中读取所有预订。最初,当用户将预订保存在数据库中时,该键claimed:的值为 “false”,这意味着清洁工尚未声明该键。
每当清洁工想要索取列表中存在的工作时,他将必须触摸按钮,该按钮将向Firebase数据库发出请求以将key的值修改claimed为trueat路径。 /Users/UID/bookings/bookingNumber
一次只能允许一名清洁工修改claimed钥匙的价值。如果允许多个清理者修改claimed密钥的值,其他清理者最终将要求相同的工作。我们不希望这种情况发生。
此外,在清理者将claimedkey 的值修改为之后true,我们将需要再次请求路径CLeaners/UID/bookings/bookingNumber以保存他刚刚在清理者节点中声明的预订。
-根据firebase的文档,每当我们希望一次仅由一个请求修改一个资源时,就会使用事务,如果有多个并发请求试图写入同一资源,则其中一个会成功。但是使用事务的问题在于,它只能写入一条路径,而不能写入多条路径。
如何确保即使有多个用户可以读取此路径 /Users/UID/bookings/bookingNumber,一次也只能更新一个用户?如果写入成功,则进一步写入第二条路径 Cleaners/UID/bookings/bookingNumber。
我们需要考虑到客户端的互联网连接可能断开,用户可以退出该应用程序,或者只是手机在写入上述指定路径之间的任何时间意外关闭。
数据库结构如下
Root
Cleaners
UID
bookings
bookingNumber
amount: “10”
claimed: “true”
Users
UID
otherID
bookingNumber
amount: “10”
claimed: “true”
bookingNumber
amount: “50”
claimed: “false”
Run Code Online (Sandbox Code Playgroud)
为了避免任何覆盖,我决定使用Firebase事务。我可以将单个节点作为事务写入,但是在完成处理程序中写入第二个节点不是解决方案,因为在从服务器接收响应之前,清洁程序的Internet连接可能会断开,或者应用程序可能会退出,因此,完成处理程序{(error, committed,snapshot) in....将不会被评估,并且第二次写入将不会成功。
另一种情况是:执行第一次写操作,
1.在客户端应用程序中收到响应
2. 在客户端应用程序中尚未收到响应
,用户立即退出该应用程序。在这种情况下,将永远不会执行第二次写操作,因为在完成处理程序中收到(或未收到)响应后,尚未评估任何代码,因此数据库处于不一致状态。
从Firebase文档:
事务不会在应用程序重启后持续存在
即使启用了持久性,事务也不会在应用程序重启后持久化。因此,您不能依赖脱机完成的事务提交到Firebase实时数据库。
是否可以使用Swift中的Firebase事务写入Firebase数据库中的多个节点?
如果是这样,我该怎么做?我在此博客中没有看到来自Google https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html的示例 。我确实知道您可以原子地写多个节点,但是我想作为事务来写。我试图在else …
将 pandas mainTable 数据帧写入 时,但在写入文件后,缺少mainTable.csv列名。
既然我已经指定了,为什么会发生这种情况?indexindex=True
mainTable.to_csv(r'/Users/myuser/Completed/mainTable.csv',index=True)
mainTable = pd.read_csv('mainTable.csv')
print(mainTable.columns)
MacBook-Pro:Completed iliebogdanbarbulescu$ python map.py
Index(['Unnamed: 0', 'name', 'iso_a3', 'geometry', 'iso_code', 'continent']
print output
Run Code Online (Sandbox Code Playgroud)
如何在Swift中生成9位数字。我尝试过random()函数,但是每次调用该函数时生成的数字的大小都不同。我也尝试过此代码在此处输入链接描述,但已弃用。
我为一个持有文本字段的原型单元创建了一个自定义的tableViewCell类.在ThirteenthViewController中,我想引用tableViewCell类,以便我可以访问其doorTextField属性,以便为其分配从UserDefaults检索的数据.我怎样才能做到这一点?
class ThirteenthViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate {
var options = [
Item(name:"Doorman",selected: false),
Item(name:"Lockbox",selected: false),
Item(name:"Hidden-Key",selected: false),
Item(name:"Other",selected: false)
]
let noteCell:NotesFieldUITableViewCell! = nil
@IBAction func nextButton(_ sender: Any) {
//save the value of textfield when button is touched
UserDefaults.standard.set(noteCell.doorTextField.text, forKey: textKey)
//if doorTextField is not empty assign value to FullData
guard let text = noteCell.doorTextField.text, text.isEmpty else {
FullData.finalEntryInstructions = noteCell.doorTextField.text!
return
}
FullData.finalEntryInstructions = "No"
}
override func viewDidLoad() {
let index:IndexPath = IndexPath(row:4,section:0)
let cell = tableView.cellForRow(at: …Run Code Online (Sandbox Code Playgroud)