Reputation: 21
public void fetchTwilioReport(){
System.out.println("fetchTwilioReport called");
Twilio.init(ACCOUNT_SID,AUTH_TOKEN);
ResourceSet<Call> calls = Call.reader().limit(20).read();
for(Call record : calls) {
System.out.println(record.getSid());
}
}
I am trying to get a list of calls, but the above code returns a blank. I am using twilio 8.11.0.
Upvotes: 0
Views: 243
Reputation: 9498
Curious. The code you have posted does fetch a list of calls for me. For clarity, here is a self-contained example of code which prints out 20 call SIDs:
package com.example;
import com.twilio.Twilio;
import com.twilio.base.ResourceSet;
import com.twilio.rest.api.v2010.account.Call;
public class CallReaderDemo {
public static void main(String[] args) {
Twilio.init(
System.getenv("TWILIO_ACCOUNT_SID"),
System.getenv("TWILIO_AUTH_TOKEN"));
ResourceSet<Call> calls = Call.reader().limit(20).read();
for (Call record : calls) {
System.out.println(record.getSid());
}
}
}
As this is in a Maven project, I have imported the Twilio Helper library in pom.xml
with:
<dependencies>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>8.11.0</version>
</dependency>
</dependencies>
If this code still returns no calls for you, then the next thing I would check is whether there actually are any calls in the account which those credentials access. Possibly "no calls" is the correct answer? You can fetch call data from the API using the same URL that the Java library does:
https://${TWILIO_ACCOUNT_SID}:${TWILIO_AUTH_TOKEN}@api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Calls.json
Replace ${TWILIO_ACCOUNT_SID}
and ${TWILIO_AUTH_TOKEN}
with your account credentials in that URL and you can load it with curl or in a web browser. The JSON that is returned will have a key calls
whose value is a list of objects full of call data.
Then there are two possibilities. If the API is returning calls and the Java Helper isn't giving them to you then we need to dig further into the Java side of things. If there are no calls and you think there definitely should be then we can look more into your account setup and take it from there. Let me know how you get on.
Upvotes: 1