hborras / twitter-php-ads-sdk

A Twitter supported and maintained Ads API SDK for PHP.
55 stars 41 forks source link

Post User to Twitter Tailored Audiences User #68

Closed urvashihirkar closed 4 years ago

urvashihirkar commented 4 years ago

I am trying to post user in audience list id(which i am creating dynamically).

Here is code i am using -:

` require '../vendor/autoload.php'; require 'config.php';

    $api =  TwitterAds::init(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);

    $responseAcc = $api->get('accounts');   
    $account = $responseAcc->getBody();
    $twAdsAccId = $account->data[0]->id;

    $response = $api->post('accounts/'.$twAdsAccId.'/tailored_audiences',array('name'=>'Test'));
    $newAudiDat = $response->getBody();
    $audienceId = $newAudiDat->data->id;

    $userJson = '{             
                   {
                      "users": [
                        {
                          "email": [
                            "c88a2aba7408c019ea7e721832cc89aeec2f91169872a977fbbe46d642c8fdd9"
                          ]
                        }
                      ]
                    }               
                }';

      $responseAudieUser =$api->post('accounts/'.$twAdsAccId.'/tailored_audiences/'.$audienceId.'/users',array('operation_type'=>'Update','params'=> $userJson));

`

But when I am printing the response it is showing error :-

caught exception 'Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError' with message 'SERVER_ERROR' in /opt/lampp/htdocs/demo/tweets-php/vendor/hborras/twitter-php-ads-sdk/src/TwitterAds.php:501

please help me so I can add user to audiecnce.

hborras commented 4 years ago

Thanks! I'll check it ASAP

hborras commented 4 years ago

Keep trying to find a good solution!

Sorry for the delay!

hborras commented 4 years ago

Hello @urvashihirkar

I've found a temporary solution. But I cannot test it until next week. App I have access to, doesn't have permissions until next week to Audience API.

Could you try this way and tell me what kind of response do you have?

PS: Download v6.0.3

$data = [
    [
        'operation_type' => "Update",
        'params' => [
            "users" => [
                [
                    "email" => [
                        "4798b8bbdcf6f2a52e527f46a3d7a7c9aefb541afda03af79c74809ecc6376f3"
                    ]
                ]
            ]
        ]
    ]
];

$responseAudieUser = $api->post('accounts/'.$twAdsAccId.'/tailored_audiences/'.$audienceId.'/users',['raw' => json_encode($data)]);