hborras / twitter-php-ads-sdk

A Twitter supported and maintained Ads API SDK for PHP.
54 stars 40 forks source link

how to schedule tweets to go live at later include text,images,gifs and videos using ads api? #70

Closed ponnnarasi14 closed 4 years ago

ponnnarasi14 commented 4 years ago

Scheduled Tweets allow an advertiser or user to create a Tweet that can be scheduled to go live at a later date, That Tweets can include text, images, GIFs, videos, or cards.

Development Languages : Laravel - php and Database - mysql

i am beginner for twitter ads api please help me to schedule post on twitter.

hborras commented 4 years ago

Download new version of the library and use this code:

<?php

use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\Account;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\ScheduledTweet;

require '../autoload.php';

const CONSUMER_KEY = '';
const CONSUMER_SECRET = '';
const ACCESS_TOKEN = '';
const ACCESS_TOKEN_SECRET = '';
const ACCOUNT_ID = '';
const USER_ID = '';

// Create twitter ads client
$api = TwitterAds::init(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);

$account = (new Account(ACCOUNT_ID))->read();

$scheduledTweet = new ScheduledTweet();

$scheduledTweet->setText("This is my Text");
$scheduledTweet->setAsUserId(USER_ID);
$scheduledTweet->setNullcast(true);
$scheduledTweet->setScheduledAt(new DateTime('tomorrow'));

$scheduledTweet->save();
ponnnarasi14 commented 4 years ago

Download new version of the library and use this code:

<?php

use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\Account;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\ScheduledTweet;

require '../autoload.php';

const CONSUMER_KEY = '';
const CONSUMER_SECRET = '';
const ACCESS_TOKEN = '';
const ACCESS_TOKEN_SECRET = '';
const ACCOUNT_ID = '';
const USER_ID = '';

// Create twitter ads client
$api = TwitterAds::init(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);

$account = (new Account(ACCOUNT_ID))->read();

$scheduledTweet = new ScheduledTweet();

$scheduledTweet->setText("This is my Text");
$scheduledTweet->setAsUserId(USER_ID);
$scheduledTweet->setNullcast(true);
$scheduledTweet->setScheduledAt(new DateTime('tomorrow'));

$scheduledTweet->save();

Thank you for your support, yeah its working. 1) when i try to scheduled tweet that can include text with 4 images and text with 1 GIF its successfully scheduled on twitter and its working fine.

2) how can i schedule tweet that can include text with 3 images and 1 GIF? - when try to scheduled tweet with 3 images and 1 gifs - its showing error - case 400: throw new BadRequest(TwitterAdsException::BAD_REQUEST, 400, null, $errors);

hborras commented 4 years ago

Hi @ponnnarasi14

Could you share the code you're executing?

Thanks

ponnnarasi14 commented 4 years ago

Hi @ponnnarasi14

Could you share the code you're executing?

Thanks

require_once dirname(FILE) . '/../../../vendor/hborras/twitter-php-ads-sdk/autoload.php';

// Create twitter ads client $api = TwitterAds::init( self::CONSUMER_KEY, self::CONSUMER_SECRET, self::ACCESS_TOKEN, self::ACCESS_TOKEN_SECRET);

$account = (new Account (self::ACCOUNT_ID))->read();

$scheduledTweet = new ScheduledTweet();

$scheduledTweet->setText("this is my tweet on twitter that can included text with 3 images and 1 GIFs sucessfully using ads api"); $scheduledTweet->setAsUserId( self::USER_ID); $scheduledTweet->setNullcast(false); $scheduledTweet->setScheduledAt('2020-03-07T09:10:00Z'); $scheduledTweet->setMediaKeys('16_1232972828565102592,3_1232913775939981312,3_1232913687767207937,3_1232236109989478400');

$scheduledTweet->save();

ponnnarasi14 commented 4 years ago

Download new version of the library and use this code:

<?php

use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\Account;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\ScheduledTweet;

require '../autoload.php';

const CONSUMER_KEY = '';
const CONSUMER_SECRET = '';
const ACCESS_TOKEN = '';
const ACCESS_TOKEN_SECRET = '';
const ACCOUNT_ID = '';
const USER_ID = '';

// Create twitter ads client
$api = TwitterAds::init(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);

$account = (new Account(ACCOUNT_ID))->read();

$scheduledTweet = new ScheduledTweet();

$scheduledTweet->setText("This is my Text");
$scheduledTweet->setAsUserId(USER_ID);
$scheduledTweet->setNullcast(true);
$scheduledTweet->setScheduledAt(new DateTime('tomorrow'));

$scheduledTweet->save();

Thank you for your support, yeah its working.

  1. when i try to scheduled tweet that can include text with 4 images and text with 1 GIF its successfully scheduled on twitter and its working fine.
  2. how can i schedule tweet that can include text with 3 images and 1 GIF? - when try to scheduled tweet with 3 images and 1 gifs - its showing error - case 400: throw new BadRequest(TwitterAdsException::BAD_REQUEST, 400, null, $errors);

Hi @hborras Sorry for the inconvenience, I got the solution, I think its not possible to scheduled tweet that can include text with images and gif! Possibility - Tweet with media must have exactly 1 gif or video or up to 4 photos.

hborras commented 4 years ago

No problem!

Thank to you!

Aksagayu commented 2 years ago

require_once dirname(FILE) . '/../../../vendor/hborras/twitter-php-ads-sdk/autoload.php';

// Create twitter ads client $api = TwitterAds::init( self::CONSUMER_KEY, self::CONSUMER_SECRET, self::ACCESS_TOKEN, self::ACCESS_TOKEN_SECRET);

$account = (new Account (self::ACCOUNT_ID))->read();

$scheduledTweet = new ScheduledTweet();

$scheduledTweet->setText("this is my tweet on twitter that can included text with 3 images and 1 GIFs sucessfully using ads api"); $scheduledTweet->setAsUserId( self::USER_ID); $scheduledTweet->setNullcast(false); $scheduledTweet->setScheduledAt('2020-03-07T09:10:00Z'); $scheduledTweet->setMediaKeys('16_1232972828565102592,3_1232913775939981312,3_1232913687767207937,3_1232236109989478400');

$scheduledTweet->save();

I have used this code,but it is not scheduling.If I pass the data without mediakeys ,it gets posted .Could you please help to resolve this issue?