-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add alt text for image uploads? #954
Comments
You should set the alt text with POST media/metadata/create. It will require three API calls.
|
Thank you for your response. I'm no OOP programmer, but I tried. I added the following functions to TwitterOAuth.php:
and
I'm calling it like this:
$result2 is giving me
I tried to json_encode the $parameters array, but that was a folly. The $parameters array within my The image upload and the status post worked fine, but of course, the alt-text did not. So it appears I'm close. What am I missing? TIA. |
I'm still trying on this and noticed an error I was making. I'm now defining $parameters as
When I json_encode this to check if it looks right, it produces:
This is the same format as given on https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create So it appears the $parameter array I'm passing is correctly set up, yet I'm still getting Can anyone see the problem? |
Hey, Did you manage to add Alt-texts to the uploading media ? |
I only managed to get it to add a empty alt tag. I think I got busy on other things and never managed to solve it. |
I followed this thread and it helped: #456
According to the thread, passing true parameter sets the content-type to json. |
$connection = new TwitterOAuth(...);
$media_payload = [
'media' => __DIR__ . '/tests/kitten.jpg',
];
$response = $connection->upload('media/upload', $media_payload);
$metadata_payload = [
'media_id' => $response->media_id_string,
'alt_text' => [
'text' => 'Good kitty',
],
];
$connection->post('media/metadata/create', $metadata_payload, true);
var_dump($connection->getLastHttpCode());
$status_payload = [
'status' => 'Hello World ' . time(),
'media_ids' => $response->media_id_string,
];
$response = $connection->post('statuses/update', $status_payload);
var_dump($response); |
Image uploading is working fine, but I want to alt text.
I tried my luck (since this is the Twitter API's syntax) with adding
'alt_text' => 'My alt text here'
as in the following block, but it fell over, and didn't post the tweet at all.How do I add alt text? TIA.
The text was updated successfully, but these errors were encountered: