Comments (13)
I don't think Twitter let's people use the old v1 API anymore. Try the v2 API.
I think it would look something like:
$connection->setApiVersion('2'); // only needed if not on the latest version of TwitterOAuth
$result = $connection->post("tweets", ["text" => $text], true);
from twitteroauth.
Hello Abraham sir,
I tried the code that you gave idea in the above response. It did not work. :(
Can you please share a working code entirely that just Prints a variable value to Twitter,, such as this variable content should be post to my twitter:
$MyTweet = 'This is my first tweet and here is my website, $WebsiteDomain #FollowMe';
from twitteroauth.
Even have tried totally new code:
function tweetViaOAuth2($bearerToken, $tweet) {
$data = array(
'text' => $tweet
);
$headers = array(
'Authorization: Bearer ' . $bearerToken,
'Content-Type: application/json'
);
$postFields = json_encode($data);
$endpoint = 'https://api.twitter.com/2/tweets';
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $endpoint,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postFields,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false
));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 201) {
echo "Tweet posted successfully.\n";
} else {
echo "Failed to post tweet.\n";
echo "HTTP error code: " . $httpCode . "\n";
$errorMsg = 'Error posting tweet: ' . $response;
auto_tweet_log($errorMsg);
}
}
$bearerToken = "AxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxGpIjfRMn";
$tweet = 'Hello Twitter! This is a test tweet via OAuth 2.0.';
tweetViaOAuth2($bearerToken, $tweet);
getting this error back :
Error posting tweet: {
"title": "Unsupported Authentication",
"detail": "Authenticating with OAuth 2.0 Application-Only is forbidden for this endpoint. Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 User Context].",
"type": "https://api.twitter.com/2/problems/unsupported-authentication",
"status": 403
}
from twitteroauth.
I don't have any Twitter apps to validate snippets. #1192 (comment) is confirming that the following should work though.
$connection->setApiVersion('2');
$result = $connection->post("tweets", ["text" => $text], true);
Bearer tokens are not valid for posting tweets. You have to go through the user oauth flow https://developer.twitter.com/en/docs/authentication/oauth-1-0a/obtaining-user-access-tokens
from twitteroauth.
Just try this:
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$connection->setApiVersion('2');
$result = $connection->post('tweets', ['text' => "Hi there!"], true);
echo $connection->getLastHttpCode() == 201 ? "Succes!" : "Failed!";
// get result:
print_r($result);
from twitteroauth.
Just try this:
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $connection->setApiVersion('2'); $result = $connection->post('tweets', ['text' => "Hi there!"], true); echo $connection->getLastHttpCode() == 201 ? "Succes!" : "Failed!"; // get result: print_r($result);
received this:
Failed!stdClass Object ( [title] => Forbidden [status] => 403 [detail] => Your client app is not configured with the appropriate oauth1 app permissions for this endpoint. [type] => https://api.twitter.com/2/problems/oauth1-permissions )
from twitteroauth.
I suggest to configure your App with the Twitter Dev platform. Remember to regenerate your keys after changing your configuration.
from twitteroauth.
I suggest to configure your App with the Twitter Dev platform. Remember to regenerate your keys after changing your configuration.
I have generated new app after removing old one from my twitter and i am building an wordpress plugin that use my Twitter Auth to send my new posts automatically to my twitter. (I dont want to use any available plugins that do the same, becuase i have something in mind that only can be achieved by custom plugin.)
from twitteroauth.
I would recommend posting to https://devcommunity.x.com/ regarding correct application configuration. Twitter seems to keep changing those.
from twitteroauth.
I suggest to configure your App with the Twitter Dev platform. Remember to regenerate your keys after changing your configuration.
I have generated new app after removing old one from my twitter and i am building an wordpress plugin that use my Twitter Auth to send my new posts automatically to my twitter. (I dont want to use any available plugins that do the same, becuase i have something in mind that only can be achieved by custom plugin.)
@Nisar2001 Ensure your app is on version 2 project in twitter dev console before you use the v2 api
from twitteroauth.
I suggest to configure your App with the Twitter Dev platform. Remember to regenerate your keys after changing your configuration.
I have generated new app after removing old one from my twitter and i am building an wordpress plugin that use my Twitter Auth to send my new posts automatically to my twitter. (I dont want to use any available plugins that do the same, becuase i have something in mind that only can be achieved by custom plugin.)
@Nisar2001 Ensure your app is on version 2 project in twitter dev console before you use the v2 api
I think, its already version 2 project and v2 API.
from twitteroauth.
I think you should test it outside the wordpress app you are working on, i mean setup something basic and test the package following the docs on twitteroauth.com
from twitteroauth.
Hi guys! I can confirm that the package is working properly with this code:
$this->twitterOAuth = new TwitterOAuth($oConfig->apiKey, $oConfig->apiSecret, $oConfig->accessToken, $oConfig->accessTokenSecret);
$this->twitterOAuth->setApiVersion('2');
$this->twitterOAuth->post("tweets", ["text" => $message]);
You can close the issue, because it's not a bug in the package, but a misconfig of the dev account.
I know because I had the same problem. The issue is due to the "Access Token and Secret" being Created with Read-only permission
instead of the correct "Read and write"
To fix it, you have to go back to Settings" and run the
User authentication set up`.
From there, you have to set Read and write
... BUT! Before you can save, you have to fill a couple of others mandatory fields. The Callback URL
field is mandatory, but not really needed: just input any URL
HTH
from twitteroauth.
Related Issues (20)
- 500 error for TwitterOAuth HOT 4
- error on callback: Cette fonctionnalité est temporairement indisponible
- Sorry, you are not authorized to see this status HOT 1
- Send clickable links to Twitter HOT 1
- Cannot attach mp4 videos HOT 8
- I want to be able to see secrete replies HOT 1
- Unable to upload media as a string (incorrect hostname used) HOT 1
- unexpected bug HOT 1
- Nice
- return NULL HOT 6
- oauth1 PUT requests doesnt work HOT 5
- I need help migrating from old twitteroauth 1.1 to new TwitterOAuth 2.0. Can anyone provide guidance? HOT 2
- Upload Media always null HOT 12
- Media IDs Are Invalid HOT 1
- account/verify_credentials returns NULL HOT 3
- Can schedule tweet HOT 1
- 403 Forbidden HOT 1
- Can't retweet in PHP HOT 2
- Video Upload On twiter api using PHP HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twitteroauth.