Skip to content

Commit

Permalink
chore: added oauth api call example
Browse files Browse the repository at this point in the history
  • Loading branch information
sbansla committed Sep 27, 2024
1 parent 8ee69fe commit 0850ea7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,8 @@ public class Example {
We are introducing Client Credentials Flow-based OAuth 2.0 authentication.
This feature is currently in beta and its implementation is subject to change.

```java
import com.twilio.credential.ClientCredentialProvider;

public class Test {
public static void main(String[] args) {
String clientId = "YOUR_CLIENT_ID";
String clientSecret = "YOUR_CLIENT_SECRET";

Twilio.init(new ClientCredentialProvider(clientId, clientSecret));
Detailed examples [here](https://github.com/twilio/twilio-java/tree/main/examples/FetchMessageUsingOAuth.md)

// Make API requests here using the authenticated client
}
}

```
### Iterate through records

The library automatically handles paging for you. With the `read` method, you can specify the number of records you want to receive (`limit`) and the maximum size you want each page fetch to be (`pageSize`). The library will then handle the task for you, fetching new pages under the hood as you iterate over the records.
Expand Down
19 changes: 19 additions & 0 deletions examples/FetchMessageUsingOAuth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import com.twilio.Twilio;
import com.twilio.credential.ClientCredentialProvider;
import com.twilio.rest.api.v2010.account.Message;

public class FetchMessageUsingOAuth {
public static void main(String[] args) {
String clientId = "YOUR_CLIENT_ID";
String clientSecret = "YOUR_CLIENT_SECRET";
String accountSid = "YOUR_ACCOUNT_SID";
Twilio.init(new ClientCredentialProvider(clientId, clientSecret), accountSid);
/*
Or use the following if accountSid is not required as a path parameter for an API or when setting accountSid in the API.
Twilio.init(new ClientCredentialProvider(clientId, clientSecret));
*/
String messageSid = "YOUR_MESSAGE_SID";
Message message = Message.fetcher(messageSid).fetch();
}
}

0 comments on commit 0850ea7

Please sign in to comment.