Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
List phone numbers opted out of Amazon SNS using an Amazon SDK
The following code examples show how to list phone numbers that are opted out of receiving Amazon SNS messages.
- Java
-
- SDK for Java 2.x
-
public static void listOpts( SnsClient snsClient) {
try {
ListPhoneNumbersOptedOutRequest request = ListPhoneNumbersOptedOutRequest.builder().build();
ListPhoneNumbersOptedOutResponse result = snsClient.listPhoneNumbersOptedOut(request);
System.out.println("Status is " + result.sdkHttpResponse().statusCode() + "\n\nPhone Numbers: \n\n" + result.phoneNumbers());
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
- PHP
-
- SDK for PHP
-
require 'vendor/autoload.php';
use Aws\Sns\SnsClient;
use Aws\Exception\AwsException;
/**
* Returns a list of phone numbers that are opted out of receiving SMS messages from your AWS SNS account.
*
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
$SnSclient = new SnsClient([
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2010-03-31'
]);
try {
$result = $SnSclient->listPhoneNumbersOptedOut([
]);
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
error_log($e->getMessage());
}
For a complete list of Amazon SDK developer guides and code examples, see
Using Amazon SNS with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.