Twillio - 找不到请求的资源Messages.json

时间:2017-12-13 12:45:57

标签: java twilio twilio-api

任何人都可以告诉我如何解决这个问题。 Java代码如下所示。

service cloud.firestore {

//This is the "root" of the database. From here we can match into our collections.
  match /databases/{database}/documents {

    //matching the collection "users", the wildcard "userId" is used for the user we will be working with.
    match /users/{userId} 
    {
    //Everyone is allowed to write, if they are logged in.
    allow write: if request.auth.uid != null;
    //A user is allowed to read, update and delete his own account.
    allow read, update, delete: if request.auth.uid == userId;
    //A user is allowed to read a user, if the user matching "userId" exists in the logged in users own subcollection of users.
    allow read: if exists(/databases/$(database)/documents/users/$(request.auth.uid)/users/$(userId));

                 //Matching the subcollection "users", still in the user matching userId.
           match /{users=**}{
           //A user is allowed to read, write, update, delete in the subcollection on his own account.
                 allow read, write, update, delete: if request.auth.uid == userId;
           //A user is allowed to read, write, update, delete in the subcollection, 
           //if the user matching "userId" exists in the logged in users own subcollection of users.
           allow read, write, update, delete: if exists(/databases/$(database)/documents/users/$(request.auth.uid)/users/$(userId));
                 }
    }

    //matching the collection "duties", the wildcard "dutyId" is used for the duty we will be working with.
    match /duties/{dutyId}{
    //Everyone is allowed to write, if they are logged in.
    allow read, write: if request.auth.uid != null;
    // A user is allowed to read, write and update if the string in the field "ownerId" in the duty matching "dutyId" == the users Uid.
    allow read, update: if resource.data.ownerId == request.auth.uid;
    //A user is allowed, if the user matching "ownerId" exists in the logged in users subcollection of users.
    allow read, update, delete: if exists(/databases/$(database)/documents/users/$(request.auth.uid)/users/$(resource.data.ownerId));
    }
  }
}

我收到以下错误:

@Service
public class TwilioServiceProvider {
    private static final String ACCOUNT_SID = 
    "ACbfadc94adf90fd6606222566aab3ef4";
    private static final String AUTH_TOKEN = "f***********************";

    public void sendMessage(String mobileNo){
        Twilio.init(ACCOUNT_SID,AUTH_TOKEN);

        Message message = Message.creator(new PhoneNumber(mobileNo),new 
         PhoneNumber("+18325323857"),"Account validation 
         successfull").create();
        System.out.println(message.getAccountSid());

    }
}

3 个答案:

答案 0 :(得分:0)

您使用的是哪个库?看起来它正在尝试发送POST到

https://api.twilio.com/2010-04-01/2010-04-01/Accounts/ACbfadc94adf90fd6606222566aab3ef4/Messages.json

但是,根据Messaging端点的twilio REST API文档,它应该是这样的:

https://api.twilio.com/2010-04-01/2010-04-01/Accounts/ACbfadc94adf90fd6606222566aab3ef4/Messages

但即使是这个网址也没有给我401未经授权,它说404,你绝对确定你有正确的账户SID吗?

也许可以尝试使用官方的twilio Java SDK,或者如果您使用的话,还可以使用更新的版本?

答案 1 :(得分:0)

Twilio开发者传道者在这里。

如果这是您在代码示例中的真实帐户Sid,那么这就是您的问题所在。我刚刚检查了我们的系统,并且账户Sid不存在。

我在Twilio console中仔细检查您的帐户Sid,然后再试一次,否则代码看起来不错。

答案 2 :(得分:0)

在我的情况下,原因是参数中的为空...

如下图所示,异常URL为THIS,但说的不多。

debug preview

Exception as debugged preview