AWS-PHP-SDK / SNS direct addressing returns error

2019-07-20 06:14发布

问题:

Hi I am using Laravel 4 setup to make use of AWS SNS to send a push message to my iOS device, the publish command to my device works well from AWS console.

I then tried from PHP:

    $sns = AWS::get('sns');

    $sns->publish(array(
        'Message' => 'Hello from PHP',
        'TargetArn' => "arn:aws:sns:us-west-2:360542326270:endpoint/APNS_SANDBOX/Testtest/20a75cd1-da25-3331-8126-4db497cbdd5e"
    ));

I am getting

Guzzle \ Service \ Exception \ ValidationException Validation errors: [TopicArn] is a required string: The topic you want to publish to.

but the docs specifically say I can use publish to either send to a topic ARN or use direct addressing to send to a single device directly.

it seems the AWS PHP SDK forces me to use TopicArn anyway.

http://aws.typepad.com/aws/2013/08/push-notifications-to-mobile-devices-using-amazon-sns.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+AmazonWebServicesBlog+(Amazon+Web+Services+Blog)

what am I doing wrong?

回答1:

I just removed the explicit guzzle line from composer. then ran update, it removed guzzle 3.6 and installed 3.9. it then removed AWS-PHP-SDK 2.3.4 and installed dev-master

I then tried it and it worked.

not sure what was the problem, but different packages versions did not work together...