我正在尝试使用 firebase 作为我的 android 应用程序的后端。但在这个早期阶段,部署到谷歌服务器并测试每个新功能和每个修复都太慢了。
我想知道是否可以在本地运行它,以便我的 Android 应用程序可以在 localhost:port 上调用 onCall() 函数?
我发现了一些 .useFunctionsEmulator(' http://localhost:8080 '); 但我不确定我需要什么导入以及如何启动本地“服务器”
我需要建议,因为我从未尝试过这种组合:
我想使用 google auth2 身份验证并“保护”仅由 android 应用程序调用的云功能,并且仅当 atuh 有效时。
最好的问候伊万
例如,这是我的“addTickets”场景的云函数:
=== index.js: ===
exports.addTickets = functions.https.onCall((data, context) => {
// data comes from client app
const buyingRecord = data;
console.log(‘buyingRecord: ‘ + JSON.stringify(buyingRecord));
return tickets.updateTicketsAmmount(buyingRecord)
.then((result)=>{
tickets.addTicketsBuyingRecord(buyingRecord);
result.userid = buyingRecord.userid;
result.ticketsCount = buyingRecord.ticketsCount;
return result;
});
});
Run Code Online (Sandbox Code Playgroud)
======门票.js ========
exports.updateTicketsAmmount = function(buyingRecord) {
var userRef = db.ref(‘users/’ + buyingRecord.userid);
var amountRef = db.ref(‘users/’ + buyingRecord.userid + ‘/ticketsAmount’);
return amountRef.transaction((current)=>{
return (current || …Run Code Online (Sandbox Code Playgroud) 我有以下结构:
root
-LKMsdf2_Qxbwtv4238D
details
uid: john
-YKMWrmj_QxbwtvSBM5A
details
uid: tony
-R45Wrmj_Qxbf321BMd4
details
uid: karina
Run Code Online (Sandbox Code Playgroud)
如何通过其 uid 找到“root”下的 ref 键:
例如:通过 uid:karina 我需要获取参考密钥 -R45Wrmj_Qxbf321BMd4
有没有办法使用一些通配符,例如 /root/{recordid}/details/uid 之类的?
======== 感谢您的提示!====这是我的最终解决方案================
findEntry = function(targetUid) {
var entriesRef = db.ref('root');
return entriesRef.once('value')
.then((snapshot)=>{
var id = []; // found id
snapshot.forEach((childSnapshot)=>{
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
var found = (childData.uid === targetUid);
if (found) {
console.log('Found for uid:' + targetUid + ': ' + childKey);
id = childKey;
}
return found; …Run Code Online (Sandbox Code Playgroud) 这是一个很好的做法,如果是的话,在不同情况下打破具有不同错误状态/消息的事务的正确方法是什么?
我有一个交易运行在一个“报价”条目上进行“座位”预订:
如果以下 3 个条件之一为真,我想中断它并将状态/消息返回给调用者函数。
如果一切正常,事务应该正常完成并将状态/消息返回到调用函数进行保留。
如果其中一个条件成立,我不确定如何中断交易。
这就是我的意思:
dealSeats = function(entryRef, data) {
const TAG = '[dealSeats]: ';
return entryRef.transaction((entry)=>{
if (entry) {
if ((entry.deals) && (entry.deals[data.uid])) {
**? how to break the transaction with state/message 'You already have a deal.' ? and how to handle it below ?**
} else if …Run Code Online (Sandbox Code Playgroud) 在我的Android应用程序中,我想让用户通过Google或Facebook帐户进行身份验证。
我已经通过Google实现了登录。我将尽快尝试通过Facebook进行登录。
我已经阅读了有关Android中的IAP的信息:
https://developer.android.com/google/play/billing/billing_overview
https://droidmentor.com/inapppurchase-subscription/
至少我了解它与Google帐户身份验证有关。
所以我想知道是否可以通过Facebook帐户对用户进行身份验证来在Android应用程序中进行IAP?
我现在找不到示例或解释。也非常感谢您与Google进行有关IAP的任何良好示例/说明,因为我对IAP尚无明确的见解。
fyi:在我的应用程序中,用户将能够购买“虚拟门票包”(例如:10、15、20张门票)并将其添加到他们的个人资料中。然后他们将一张一张地“消费”门票。
最好的祝福