I use TwitterOauth, a Abraham Williams library for Twitter API.
I want upload a media to insert into Direct Message.
I've an error when I try to upload base64 encode PNG image, with chunked, or not.
$upload = $connection->upload('media/upload', [
'media_data' => $base64Encoded,
'media_type' => 'image/png',
], true); // chunked
dd($upload);
Some people talk about passing media_data to media and giving the path to the file, but the Twitter API allows to give base64 encoded media, so I'm trying to make it work because I don't want to transfer the media to the server before uploading it to Twitter, even temporarily, because I don't have write access to the server.
So I generate a base64 image, and I just want to upload it to Twitter via the API and TwitterOauth SDK.
The image is generated with PHP, I encode it in base64. I want to upload directly to the Twitter API without saving the image. Twitter API allows this with the media_data parameter, but I can't figure out how to use it.
Here, the error I have when I execute the script.
How I can upload media from Twitter API?
According to https://github.com/abraham/twitteroauth/issues/681, that problem is worked on since some years, but without any progress. If the library does not support reading from a raw string yet, you should either write your raw string to a file (because reading data from a file to upload that data is supported), or you could work on that ticket to get it done within the library.
That's the beauty of open source: if a library does not support your needs, you can extend it and make others happy that might have the same problem :)
Related
I am creating an API-centric web application using PHP. I have read a lot of articles on API-centric arhitecture and design, but I have a problem related to file uploads.
Suppose I have an image and I want to upload it to the API server. How should I upload that image and how then to receive the link to that image?
Here is how I want to create it now:
Select an image using <input type="file"> on client www.domain.com
Upload it to the www.domain.com using POST with multipart/form-data
Send this image with PUT/POST API call to the api.domain.com
api.domain.com will save this image to another server like static.domain.com and will store image's id in the database
Then, when I will need this image, I can use GET API call to the api.domain.com and I will receive image's url (something like static.domain.com/image.jpg)
Aditional questions:
Is this approach the right one or I am doing completely wrong?
Will I need an aditional server to store uploaded files if my application will be small, or I can store files right on the API server?
If I will store images on same server as API server, won't it be strange if image urls will look like api.domain.com/image.jpg?
P.S: We can skip a lot of API-related things as I need only an idea on how to deal with file uploads.
You haven't really said what kind of API that you are going to be implementing here, so I assume that it is just a restful API.
Is this approach the right one or I am doing completely wrong?
No, I wouldn't say you're doing it wrong. You would essentially send the file using POST.
Will I need an aditional server to store uploaded files if my application will be small, or I can store files right on the API server?
Yes, it will allow you to store this on the same server, I don't see why not. I doubt that you will use a lot of storage, if the application is small.
If I will store images on same server as API server, won't it be strange if image urls will look like api.domain.com/image.jpg?
The api.domain.com/image.jpg technically is just the URL that you connect to the API with and GET/POST data. It does not mean the file is going to be that URL. The API could return like:
{
type: "IMG",
id: "1",
url: "example.com/uploads/image.jpg"
}
I hope this this helps, even a little!
Let's imagine that I have a video url on my site: it's like this: http://example.com/videos/myvideo.mp4 . I want to use Automatic (“pull”) uploads method to upload this video to vimeo. Then I simply want to host it on my site. The problem is that the documentation that they provide is kinda confusing to me (and possibly all other developers getting started with their api). So, from your experience can you tell me how to upload this video to that vimeo and get back the video url that has been uploaded?
I created the vimeo app as they said and I have requested the upload access. It says:
Upload Access
Approved for the following accounts:
Your account
So basically everything is setup. I just need to know what http request should I send to the vimeo server in order to upload that mp4 file that is accessible on the web.
The HTTP request is detailed in the pull upload section of the documentation: https://developer.vimeo.com/api/upload/videos#automatic-pull-uploads
An HTTP POST request to https://api.vimeo.com/me/videos with two required, and one optional parameter sent through the request body.
The official PHP library: https://github.com/vimeo/vimeo.php will help you make the upload request, and documentation on making requests using this library is located here: https://github.com/vimeo/vimeo.php#make-requests
Once you have all the pieces together, the request looks kind of like this:
$response = $lib->request('/me/videos', ['type'=>'pull','link'=>$url], 'POST');
I have seen many posts through which we can upload image on S3, but what if we want to save image from google/facebook , that is something like graph.facebook.com/abc.img (suppose it is a valid image)
I have seen a similar post but that uses Node.js but I simply want to use php to save image on s3,
any help in this matter is appreciated Thanks
You could use this Facebook SDK PHP Class:
https://developers.facebook.com/docs/reference/php/4.0.0
And this one for S3:
https://github.com/tpyo/amazon-s3-php-class
Get the image from Facebook with the Graph API.
Upload it to S3 with the Amazon S3 PHP Class
Should be pretty easy ;)
I have Implemented an WhatsAPI - PHP on my site, but am only able to
send messages but not the Media files like Images, Audio or Video.
I got the WhatsApp API for PHP
This is my screen.
I am not getting how to send an image or any other media files through this API.
I have tried all url for image sending like.
http://www.sample.com/images/sample.jpg
C:\Users\Public\Pictures\Sample Pictures\sample.jpg
But it still not able to send any media file.
Please let me know how to send an image from this API. What am doing wrong....?
as i read the example functions in the API files you will see this,
//send picture
$w->sendMessageImage($target, "demo/x3.jpg");
and of this code you may need to pass the image absolute url to the api
since you are working on localhost, you may not success sending the image, you may need to try it on real server.
and the image should be on same server NOT external image url
I Hope this also will work. Please try and let us know the result.
while($w->pollMessage()); after $w->sendMessageImage($target, "demo/x3.jpg");
How to upload an audio file in facebook using graph api in php? use
feed or anything i can't figure out how to upload?
As far as I know this is not possible. You can only upload photos and videos. But you could host your audio objects on your site and share them via the Opengraph Audio ComplexType. See the reference here: https://developers.facebook.com/docs/opengraph/creating-custom-stories#propertytypes