what path is actually in source?:
$photo = $facebook->api("/me/photos", "POST", array(
source => "#" . "YOUR_IMAGE_PATH",
message => "YOUR_MESSAGE"
));
Image path from the server (should I upload image first to my server?) or $_FILES['photo']['tmp_name']?
I just get CurlExceptionfailed creating formpost data
Where can I get image path?
Thanks
Related
I'm trying to upload a file with presigned AWS url.
I generate a presigned url like that :
use AsyncAws\S3\S3Client;
$s3 = new S3Client();
$bucket = 'my-bucket';
$key = 'myfile.pdf';
$date = new \DateTimeImmutable('+15minutes');
$contentType = 'application/pdf';
$input = new GetObjectRequest([
'Bucket' => $bucket,
'Key' => $key,
'ContentType' => $contentType
]);
$presignUrl = $s3->presign($input, $date);
This code above works fine, I get a presigned url like this : "https://my-bucket.s3.eu-west-3.amazonaws.com/myfile.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20220809T141153Z&X-Amz-Expires=900&X-Amz-Credential=XXXXXXXXXXXXXXX%2F20220809%2Feu-west-3%2Fs3%2Faws4_request&x-amz-content-sha256=UNSIGNED-PAYLOAD&X-Amz-SignedHeaders=host&X-Amz-Signature=XXXXXXXXXXXXXXXXXXXXXXXXXX"
Next, I try to use this url to upload a file with Postman.
I select my pdf file via Body / binary / Select file
This is my postman config and response :
As you can see, I have a 403 code response.
These are my headers (of course I've tried with differents Content-Type but nothing better than the exactly same 403 response.
Important information : With the same $s3 instance and authentification, if I try to get object url ($content = $s3->getObject($input); with AsyncAws), it works well. So I suppose, it is not an authentification issue.
Thanks in advance if you have any idea for me !
I need a script to take my text, convert it to speech using AWS Polly API and save it on my server as mp3 file.
Currently when I load a page a player appears and plays back the speech clip but no file is downloaded.
What am I missing?
require '../../../include/lib/aws/aws-autoloader.php';
// Creating Amazon Polly Client
use Aws\Polly\PollyClient;
$config = [
'version' => 'latest',
'region' => 'us-west-2', //region
'credentials' => [
'key' => 'MY_KEY',
'secret' => 'my_AWS_secret',
]];
$client = new PollyClient($config);
// Converting Text to Speech via Polly API
$args = [
'OutputFormat' => 'mp3',
'Text' => "<speak><prosody rate='medium'>My text goes here..</prosody></speak>",
'TextType' => 'ssml',
'VoiceId' => "Joanna",
];
$result = $client->synthesizeSpeech($args);
$resultData = $result->get('AudioStream')->getContents();
// Listening the text
$size = strlen($resultData); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
header('Content-Transfer-Encoding:chunked');
header("Content-Type: audio/mpeg");
header("Accept-Ranges: 0-$length");
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: $length");
echo $resultData;
// Download the Text to Speech in MP3 Format
header('Content-length: ' . strlen($resultData));
header('Content-Disposition: attachment; filename="./myfile.mp3"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
echo $resultData;
Your sending 2 responses one after the other. The first will be processed the second most likely will be ignored.
Basically you cant send headers after you already sent content. Refactor your code so you only send 1 response per request.
simply save the output in a new file:
file_put_contents("output.mp3", $resultData);
{ file_put_contents("output.mp3", $resultData);
This command worked for me as I was able to download the file on my local desktop
I am uploading PDF's to AmazonS3 manually, using Panic Transmis and via a PHP script/API.
For some reason, some display in your browser, and some force download.
I have checked permission and can not seem to see any issues, Can anyone help explain how to make PDF's always display in browser ( unless the user specifies otherwise ).
I don't think it is as browser issue.
You need to change the Content-Type and Content-Disposition.
Content-Type: application/pdf;
Content-Disposition: inline;
Using the AWS S3 console, find the file and using the context menu (right click) select Properties then it's under Metadata.
Or change this programmatically:
http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/create_object
In companion with well's answer, here an example:
public function save($bucket, $name, $content, $options = [])
{
$this->s3->putObject([
'Bucket' => $bucket,
'Key' => $name,
'Body' => $content,
] + $options);
}
$this->bucket->save('my-bucket', 'SofiaLoren.pdf', $content, [
'ContentType' => 'application/pdf',
'ContentDisposition' => 'inline',
]);
At the moment I have to download images on the server and post them like this:
$photo = array(
'message' => 'Status',
'source' => '#/full/path/of/the/image.png'
);
$response = $fb->api('/'.$album.'/photos', 'POST', $photo);
I'm using curl on the backend to post this request and it's working like a charm.
I'm wondering if it's possible to post the remote image directly instead to download a local copy?
I tried to do something like this:
$photo = array(
'message' => 'Status',
'source' => file_get_contents('http://www.domain.com/image.png')
);
$response = $fb->api('/'.$album.'/photos', 'POST', $photo);
But I got an exception from the graph API: "(#324) Requires upload file"
It looks like this is happening when you are not sending the multipart/data header which is set automatically when sending an array of data ($data is an array).
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
So I'm doubtful that it's possible to post a remote image.
What do you think?
It is possible to upload a photo by just giving that photo’s URL under the parameter name url.
This info is a little hidden in the description of the photo endpoint, where it just says,
“You can also publish a photo by providing a url param with the photo's URL.”
So instead of providing the sourceparameter, just provide url with the value of the photo’s publicly reachable URL. (All other parameters except source stay the same and are still usable in the same way.)
I tried this recently, and it worked fine. Although, I only tried it for photos with URLs from my app domain – I can’t say for sure if it works for URLs from “anywhere” on the web as well (although i can’t see a good reason for why it shouldn’t).
brand new here.. I've looked everywhere, couldn't find an answer.. :/ Hopefully someone here can help me out. I'm using the graph api to upload a photo, and tag the user in it. This is currently working great. I would like to show the user the image, in the album, so I need the image id to generate the url. I cannot figure out how to do this!! Below are the lines of code that upload/tag the photo, to my app's album. What do I need to do to get this image id? Thanks a lot! -Tim
$user = $facebook->getUser();
function post_image($facebook, $user,
$image_path){
try{ $tag = array(
'tag_uid' => $facebook->getUser(),
'x' => 0,
'y' => 0
);
$tags[] = $tag;
$image = array(
'message'=> 'Your Banner Photo', 'tags' => $tags,
);
$facebook->setFileUploadSupport(true);
$image['image'] = '#'.realpath($image_path);
$facebook->api('/me/photos', 'POST', $image);
echo "";
return true;
}catch(FacebookApiException $e){
echo $e;
return false;
} }
Sadly, you have to do it as a separate query. You have to get the users galleries (first graph API call). then find the gallery ID you want and request the photos (second graph API call) then parse through the photos to find the one you want. Finally you have to request that photo.
-------------------Update:---------------------------
I'm not a very proficient php developer, but i use facebook api all the time with javascript or actionscript. The basic premise is to call the graph api, and it will return a json object of the result. Use getFile or Curl to load the graph api responses.
You can test your graph api calls here:
https://developers.facebook.com/tools/explorer/?method=GET&path=663032752
so try and walk that through from the graph api. Get the user galleries, then get the photos, then get the one you want.
To get the albums, call
"https://graph.facebook.com/me/albums?access_token="._accessToken;
To get the photos in an album you call it using:
https://graph.facebook.com/"._albumID."/photos?access_token="._accessToken;
And then to get the individual photo you would get the photo's ID property and call that.
sometihng like:
"https://graph.facebook.com/".your_photo_id;
I think using CURL is a good approach, but I'm weak on php, so use what you are comfortable with.
You have the photo ID in facebook API response, if it is uploaded successfully:
$result = $facebook->api('/me/photos', 'POST', $image);
echo $result['id'];