abraham / twitteroauth

The most popular PHP library for use with the Twitter OAuth REST API.
https://twitteroauth.com
MIT License
4.3k stars 1.71k forks source link

I need help migrating from old twitteroauth 1.1 to new TwitterOAuth 2.0. Can anyone provide guidance? #1215

Closed cyberfunk closed 9 months ago

cyberfunk commented 10 months ago

I'm using the below PHP code with latest Abraham TwitterOAuth 6.2.0 to tweet from my macOS desktop. I have PHP and Composer installed and running. When I send a tweet using the PHP terminal command it seems to work but my timeline at Twitter is empty so something is wrong somewhere. If anyone can look at the code and hep me fix it and get it up and runing I would be grateful. I have PHP 8.3 installed on macOS Big Sur.

`<?php require_once "/Users/macOS/Projects/Twitter/vendor/autoload.php";

use Abraham\TwitterOAuth\TwitterOAuth;

define('CONSUMER_KEY', ''); define('CONSUMER_SECRET', ''); define('ACCESS_TOKEN', ''); define('ACCESS_TOKEN_SECRET', '');

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $connection->setApiVersion('2');

$status_payload = [ 'text' => 'Hello World ' . time(), ];

$response = $connection->post('tweets', $status_payload, true);

?>`

hizmarck commented 9 months ago

@cyberfunk This issue is more suitable for StackOverflow, I tested the library and I'm was able to sent tweets. Btw you code seems to be correct, so maybe the problem came from other front.

cyberfunk commented 9 months ago

@cyberfunk This issue is more suitable for StackOverflow, I tested the library and I'm was able to sent tweets. Btw you code seems to be correct, so maybe the problem came from other front.

Thanks for the follow up. I ended up switching to an excellent Ruby based Twitter (X) solution: https://github.com/sferik/x-ruby and running it natively from my laptop using Cron on macos! It turns out my cheap website hosting plan does not include the ability to load composer and other dependencies required by the Abraham library. My old server provider inlcuded all of those dependencies which is why it worked so well for so long. All the best!