Closed lucaschevalierr closed 8 months ago
Same here. My code
<?php
require "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$connection->setApiVersion(1.1);
$connection->setTimeouts(10, 15);
$media1 = $connection->upload('media/upload', ['media' => '/code/test.mp4','media_type' => 'video/mp4', 'media_category' => 'tweet_video']);
print_r($media1);
print_r("Why are you null?");
$connection->setApiVersion(2);
$parameters = [
'text' => 'Meow Meow Meow',
'media' => ['media_ids' => [$media1->media_id_string]]
];
$result = $connection->post('tweets', $parameters);
@lucaschevalierr Solved it! Use the chunk upload.
$media1 = $connection->upload('media/upload', ['media' => '/code/test.mp4','media_type' => 'video/mp4', 'media_category' => 'tweet_video'], ['chunkedUpload' => true]);
@ProdigyView It doesn't work for me... I try to do this :
$media = $connection->upload(
'media/upload',
[
'media' => 'imgs/test.jpeg',
'media_type' => 'image/jpeg',
'media_category' => 'tweet_image'
],
['chunkedUpload' => true]
);
And i have this error : property_exists(): Argument #1 ($object_or_class) must be of type object|string, null given
I would the the absolute page to your image:
'media' => 'imgs/test.jpeg',
I would the the absolute page to your image:
'media' => 'imgs/test.jpeg',
I already try, but it doesn't work either
Anyone have an idea?
And i have this error : property_exists(): Argument #1 ($object_or_class) must be of type object|string, null given
What's the rest of the error? What method is getting an invalid value?
And i have this error : property_exists(): Argument #1 ($object_or_class) must be of type object|string, null given
What's the rest of the error? What method is getting an invalid value?
Here is the rest of the error :
If you are not on the latest version of TwitterOAuth you would need to use the old method of setting chunkedUpload
$media = $connection->upload(
'media/upload',
[
'media' => 'imgs/test.jpeg',
'media_type' => 'image/jpeg',
'media_category' => 'tweet_image'
],
true
);
If you are not on the latest version of TwitterOAuth you would need to use the old method of setting
chunkedUpload
$media = $connection->upload( 'media/upload', [ 'media' => 'imgs/test.jpeg', 'media_type' => 'image/jpeg', 'media_category' => 'tweet_image' ], true );
So I ran some tests:
When I use the Client ID and Client Secret in the variables $consumerKey and $consumerSecret WITH ['chunkedUpload' => true], I get this error:
When I use the Client ID and Client Secret in the variables $consumerKey and $consumerSecret WITHOUT ['chunkedUpload' => true], I get this error:
When I use the API Key and API Key secret in the variables $consumerKey and $consumerSecret WITH ['chunkedUpload' => true], I get this error:
When I use the API Key and API Key secret in the variables $consumerKey and $consumerSecret WITHOUT ['chunkedUpload' => true], I get "null":
PS: I think I am using the latest version of TwitterOAuth because when I try your code, I get this error: "Expected type 'array'. Found 'true'.”
PS2: Thank you very much for the time you spend helping me.
I think you have an authentication issue. To use that API you need client credentials and user credentials. You would want to use the the values with the following names. You'd also need to make sure that the user has granted write permissions for that token and if the user had previously granted read only permissions, the app needs to be revoked and authorized again.
$connection = new TwitterOAuth('API Key', 'API Secret', 'Access Token', 'Access Token Secret');
I think you have an authentication issue. To use that API you need client credentials and user credentials. You would want to use the the values with the following names. You'd also need to make sure that the user has granted write permissions for that token and if the user had previously granted read only permissions, the app needs to be revoked and authorized again.
$connection = new TwitterOAuth('API Key', 'API Secret', 'Access Token', 'Access Token Secret');
OMG, the last time I created the token I didn't have the right permissions, I didn't see that it was here.
Thank you and really sorry...
What are you attempting to do I'm trying to upload a photo, but my result is always null...
I was inspired by what was done here: https://stackoverflow.com/questions/76504748/twitter-api-v2-create-tweet-with-media-php/76505243#76505243
Here's my code:
Versions:
Additional context I also tried not specifying the API version, adding parameters like media type, but nothing worked.