I'm trying to post a photo using the php-sdk - all was working for months successfully but all of the sudden no dice.
Other functions are still working with the same code base (ie: posting messages to wall) - its just the posting of photos that broke on my side.
try {
$data = $facebook->api('/me/photos', 'post', $args);
} catch (FacebookApiException $e) {
print_r($e);}
Is dumping:
FacebookApiException Object ( [result:protected] => Array ( [error_code] => 3 [error] => Array ( [message] => No URL set! [type] => CurlException ) ) [message:protected] => No URL set! [string:private] => [code:protected] => 3 [file:protected] => /locationofmy/base_facebook.php [line:protected] => 818 [trace:private] => Array ( [0] => Array [..............]
From the FB php-sdk lines 818:
if ($result === false) {
$e = new FacebookApiException(array(
'error_code' => curl_errno($ch),
'error' => array(
'message' => curl_error($ch),
'type' => 'CurlException',
),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
return $result;
}
This was working for a long time - has something changed on Facebooks side?
EDIT: php-sdk version: 3.1.1
EDIT 2:
$tag = array(
'tag_uid' => 'acct_num',
'x' => 0,
'y' => 0
);
$tags[] = $tag;
$args = array(
'message' => $item_description,
'image' => '#' . realpath($temp_path . $tempFile),
'tags' => $tags,
);
Probably that the file doesnt exist, or the file system can't serve it anymore. Can you confirm "$temp_path . $tempFile" - the error is no URL, usually that means no real path to image. I suspect, that the images are missing and/or your servers filled up and no local images are saving. (Yes, this has happened to me before!)
Try changing the image to source. I believe this should fix your issue.
The Facebook API requires a source field but I did not see anything about an image field.
You may also have to pass the actual file contents instead of the real_path (based on the example). Or, alternatively, pass an external URL (based on my understanding of the documentation).
Source: https://developers.facebook.com/docs/reference/api/photo/
Example: https://developers.facebook.com/blog/post/498/
Related
I am trying to get Polly to read something for me, using PHP.
I have created a new project, installed Amazon composer require aws/aws-sdk-php and then created a file with code from SDK documentation example and modified a few minor things such as changing credential from default to value, var_dump to var_export and finally saved the content of the stream to file
<?php
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
use Aws\Polly\PollyClient;
use Aws\Credentials\Credentials;
// Create a PollyClient
$client = new Aws\Polly\PollyClient([
//'profile' => 'default',
'credentials' => new Credentials('XXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),
'version' => '2016-06-10',
'region' => 'us-east-2'
]);
try {
$result = $client->synthesizeSpeech([
'Text' => 'Hello',
'OutputFormat' => 'json', //json|mp3|ogg_vorbis|pcm
'VoiceId' => 'Joanna',
]);
var_export($result);
$data = $result->get('AudioStream')->getContents();
echo "\n\n";
var_export($data);
$file = fopen('test.txt','w+');
fwrite($file,$data);
fclose($file);
} catch (AwsException $e) {
echo $e->getMessage() . "\n";
}
The result I'm getting is following
Aws\Result::__set_state(array(
'data' => array (
'AudioStream' => GuzzleHttp\Psr7\Stream::__set_state(array(
'stream' => NULL,
'size' => NULL,
'seekable' => true,
'readable' => true,
'writable' => true,
'uri' => 'php://temp',
'customMetadata' => array (),
)),
'ContentType' => 'application/x-json-stream',
'RequestCharacters' => '5',
'#metadata' => array (
'statusCode' => 200,
'effectiveUri' => 'https://polly.us-east-2.amazonaws.com/v1/speech',
'headers' => array (
'x-amzn-requestid' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'x-amzn-requestcharacters' => '5',
'content-type' => 'application/x-json-stream',
'transfer-encoding' => 'chunked',
'date' => 'Sat, 18 Sep 2021 05:11:20 GMT',
),
'transferStats' => array (
'http' => array (
0 => array (),
),
),
),
),
'monitoringEvents' => array (),
))
''
As you can see the size of the AudioStream is null (nothing in it) and also the created file is also empty since there is nothing in the stream to read.
If I change a credential to an invalid string, I get errors, and with the valid credential, the status code is 200, which makes me believe that my request is successful.
I changed voiceId to any other valid or invalid id and even changed the region with others with valid values getting status 200 and with invalid ones getting error messages, but I'm still not getting anything out of polly, it doesn't feel like talking!
Note: When I run $arr_voices = $polly->describeVoices();, I can read list of the voices without error.
Note: I had the same issue with .NET SDK too, which makes me think either there is something wrong with my request or some error message is missing from API.
Question
What I'm doing wrong?
You're not doing anything wrong, but it only outputs JSON if you're looking for speech marks. Try switching to an audio output format like MP3 as shown below.
$result = $client->synthesizeSpeech([
'Text' => 'Hello',
'OutputFormat' => 'mp3', //json|mp3|ogg_vorbis|pcm
'VoiceId' => 'Joanna',
]);
If you're looking for speech marks- metadata on the speech that will be synthesized- you need to specify SpeechMarkTypes as shown here https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-polly-2016-06-10.html#synthesizespeech
Since Soap errors are WSDL specific I'm asking this question. I'm trying to add a relation in an online accountancy application. Authenticating and getting works just fine.
This is the code I'm using (Security code and SessionID are working fine when Getting relations):
$params = array( "input" => array( "SecurityCode2" => $SecurityCode2,
"SessionID" => $SessionID,
"cRelatie" => array(
"ID" => NULL,
"AddDatum" => date("Y-m-d h:i:s"),
"Code" => "PUBID".sprintf('%04d', $vve['id']),
"Bedrijf" => $Bedrijf,
"Contactpersoon" => $Contactpersoon
)
)
);
try {
$response = $client->__soapCall("AddRelatie", $params);
}
catch (Exception $e){
echo 'Caught exception: ', $e->getMessage(), "\n";
}
I've also tried nesting the cRelatie within an array with one index called oRel (see WSDL), but that didn't work either.
Error:
Caught exception: Server was unable to process request. ---> Object reference not set to an instance of an object.
This is the WSDL location
https://soap.e-boekhouden.nl/soap.asmx?wsdl
Got it working:
There where non documented required fields
And date wasn't allowed to have time, In contrary to the WSDL
$params = array( "input" => array(
"SecurityCode2" => $SecurityCode2,
"SessionID" => $SessionID,
"oRel" => array(
"ID" => 0,
"Gb_ID" => 0,
"GeenEmail" => 0,
"NieuwsbriefgroepenCount" => 0,
"AddDatum" => date("Y-m-d"),
"Code" => "PUBID".sprintf('%04d', $vve['id']),
"Bedrijf" => $Bedrijf,
"Contactpersoon" => $Contactpersoon
)
));
I'm trying to create a PHP script that creates a function from some code that i zip up on our server. I uploaded the file manually to lambda, and it works fine. But when i try to use the aws sdk to create the function, it fails with an error message. Anyone got any clue?
Code:
private function createLambdaFunction() {
$result = $this->lambdaConn->createFunction(array(
'FunctionName' => $this->lambdaFunctionName,
'Runtime' => $this->runtime,
'Role' => $this->role,
'Handler' => $this->lambdaFunctionName.".".$this->handler,
'Description' => $this->description,
'Timeout' => $this->timeout,
'MemorySize' => $this->memorySize,
'Code' => array(
'ZipFile' => 'fileb://test.zip'
)
));
Error:
PHP Fatal error: Uncaught Aws\Lambda\Exception\LambdaException: AWS
Error Code: InvalidParameterValueException,
Status Code: 400, AWS Request ID: asdf, AWS Error Type: user,
AWS Error Message: Could not unzip uploaded file. Please check
your file, then try to upload again., User-Agent:
aws-sdk-php2/2.8.10 Guzzle/3.9.3 curl/7.35.0 PHP/5.5.9-1ubuntu4.9
I can't seem to find a good example on google, and the documentation is...less than ideal. I created the zip file with php, so I've tried passing that var, the full path to the file, relative path to file, etc. Finally learned you have to use fileb:// preface, but that didn't end up fixing anything.
Okay, I'm not sure why this is the case, but you need to base64 encode your zip file like:
$result = $this->lambdaConn->createFunction(array(
'FunctionName' => $this->lambdaFunctionName,
'Runtime' => $this->runtime,
'Role' => $this->role,
'Handler' => $this->lambdaFunctionName . "." . $this->handler,
'Description' => $this->description,
'Timeout' => $this->timeout,
'MemorySize' => $this->memorySize,
'Code' => array(
'ZipFile' => 'fileb://'.base64_encode(file_get_contents('test.zip'))
)
));
I'm not sure why this is required, as accourding to the doumentation and a post by an AWS employee, you dont have to have base64 encoding for create function. They must have mixed up something or another.
i am using codebird-php to post images on twitter, when i do that i get 200 ok http code but the image is not uploaded. Here is my code:
<?php
session_start();
require_once ('./src/codebird.php');
\Codebird\Codebird::setConsumerKey('74AFitlDilqB2HlFQ8Cjszz6I', 'tDlVndY7iJG8loFGG1sq3gJaj59CwNx6UV5o6wEtV0LJebNJ0y'); // static, see 'Using multiple Codebird instances'
$cb = \Codebird\Codebird::getInstance();
$access_token = $_SESSION['access_token'];
$cb->setToken($access_token['oauth_token'], $access_token['oauth_token_secret']);
//$reply = $cb->statuses_update('status=Whohoo, I just again tweeted!');
// send tweet with these medias
$reply = $cb->media_upload(array(
'media' => 'http://www.bing.com/az/hprichbg/rb/BilbaoGuggenheim_EN-US11232447099_1366x768.jpg'
));
print_r($reply);
?>
This is what i am getting on running it in my browser:
stdClass Object ( [media_id] => 540134777223790592 [media_id_string] => 540134777223790592 [size] => 179801 [image] => stdClass Object ( [w] => 1366 [h] => 768 [image_type] => image/jpeg ) [httpstatus] => 200 [rate] => )
PS: I am running it on localhost, tweeting text works but not image and i am using Abrahams oAuth for getting oAuth token.
i fixed it by changing
$reply = $cb->media_upload(array(
'media' => 'http://www.bing.com/az/hprichbg/rb/BilbaoGuggenheim_EN-US11232447099_1366x768.jpg'
));
to
$params = array(
'status' => 'Auto Post on Twitter with PHP http://goo.gl/OZHaQD #php #twitter',
'media[]' => 'http://www.bing.com/az/hprichbg/rb/BilbaoGuggenheim_EN-US11232447099_1366x768.jpg'
);
// send tweet with these medias
/*$reply = $cb->media_upload(array(
'media[]' => "#http://www.bing.com/az/hprichbg/rb/BilbaoGuggenheim_EN-US11232447099_1366x768.jpg"
));*/
$reply = $cb->statuses_updateWithMedia($params);
I am trying to upload a Product Image to Shopify via POST-ing a Base64 image to the API with OhShopify PHP library fork.
I have other code which successfully creates the product, but this snippet below returns NULL and I can't pinpoint why.
This code runs seemingly successfully 'makes it' and creates a new ShopifyClient object, but the var_dump on the $response['src'] returns NULL and the image never makes it. Am I missing something?
<?php
define('SHOPIFY_API_KEY', 'abc');
define('SHOPIFY_SECRET', '123');
define('SHOPIFY_SCOPE', 'write_content,write_products,write_orders');
include_once('lib/ohShopify/shopify.php');
// Check for shopify authentication
if (isset($_SESSION['shop']) && isset($_SESSION['token'])){
$shopifyClient = new ShopifyClient($_SESSION['shop'], $_SESSION['token'], SHOPIFY_API_KEY, SHOPIFY_SECRET);
echo 'made it';
} else{
echo 'token and shop not set up';
}
$testBase64 = "loooooooooooooong string of text";
try {
$theImages = array
(
"image"=>array
(
"position" => 1,
"attachment" => $testBase64
)
);
$response = $shopifyClient->call('POST', '/admin/products/#326021139/images.json', $theImages);
var_dump($response['src']);
} catch (ShopifyApiException $ex) {
var_dump($ex);
}
?>
The images array is 1 more array :
$image = file_get_contents("Images/test.jpg");
$base64 = base64_encode($image);
$products_array = array
(
'product' => array
(
'title' => $_POST['title'],
'body_html' => $_POST['body_html'],
'vendor' => $_POST['vendor'],
'product_type' => $_POST['type'],
'images' => array(
array(
'filename' => 'test.jpg',
'attachment' => $base64
)
)
)
);
If you base64 encode your image, it also works from local files.
The only thing you did wrong was the extra array at images:
$image = file_get_contents("Images/test.jpg");
$base64 = base64_encode($image);
$products_array = array
(
'product' => array
(
'title' => $_POST['title'],
'body_html' => $_POST['body_html'],
'vendor' => $_POST['vendor'],
'product_type' => $_POST['type'],
'images' => array(
array(
'filename' => 'test.jpg',
'attachment' => $base64
)
)
)
);
Stack Overflow suffers with all the drive-by zealots down voting posts/questions without a statement as to their reasons. If you have a reason, then please pontificate rather then being an anonymous coward.
For those having the same issue or question, I ultimately could NOT get this to work but came up with a solution that I would initially take the base64 encoded image, save it as a file on server, then pass the URL of the file to a Product creation API call.
Essentially:
file_put_contents( 'img_uploads/'.$filename, base64_decode($encoded_img) );
...
try {
// Create a new product
$product = array
(
"product"=>array
(
"title"=>$title,
"body_html"=>$body_html,
"vendor"=>$vendor,
"product_type"=>$productType,
"variants"=>array ("price"=>$price),
"images"=>array ("src"=>$image)
)
);
$response = $shopifyClient->call('POST', '/admin/products.json', $product);