I'm setting up a Cloudinary listing of uploaded videos and I want to get the metadata of that video.
I have a print_r($result):
<pre>
Cloudinary\Api\Response Object
(
[rate_limit_reset_at] => 123123123
[rate_limit_allowed] => 123
[rate_limit_remaining] => 123
[storage:ArrayObject:private] => Array
(
[public_id] => dog
[format] => mp4
[version] => 123123123
[resource_type] => video
[type] => upload
[created_at] => 2019-07-29T07:32:50Z
[bytes] => 123123
[width] => 321
[height] => 456
[backup] => 1
[access_mode] => public
[url] => http://res.cloudinary.com/demo/video/upload/dog.mp4
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.mp4
[next_cursor] => 123123123
[derived] => Array
(
[0] => Array
(
[transformation] => /jpg
[format] => jpg
[bytes] => 86438
[id] => 123123123
[url] => http://res.cloudinary.com//demo/video/upload/dog.jpg
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.mp4
[extension] => jpg
)
[1] => Array
(
[transformation] => t_media_lib_thumb/jpg
[format] => jpg
[bytes] => 3293
[id] => 12123123
[url] => https://res.cloudinary.com/demo/video/upload/dog.jpg
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.jpg
[extension] => jpg
)
)
)
)
</pre>
I tried getting the value using this format but it says undefined index. echo $result[4]['width'] or echo $result['storage:ArrayObject:private']['width'];
I talked to a cloudinary support ad he said that "you should be able to access the data returned within [storage:ArrayObject:private] by simply ignoring it and requesting the index that you desire directly from $result. Meaning you can use or and so on with the other paramters."
So basically, just removing the index solved my problem like so:
<?php echo $result['height']; ?> <?php echo $result['width']; ?>
Have a look at this https://github.com/cloudinary/cloudinary_php/blob/master/src/Api/Response.php in order to better understand the object you are getting back.
Afterwards, look at the ArrayObject documentation here https://www.php.net/manual/en/class.arrayobject.php, as your Response object extends this class. Using getArrayCopy() to transform your object into an array should be what you need.
Bear in mind that I am not familiar with the API and that there may be better options to get what you need.
Related
I have all the boards of logged in user and using pinterest api i am able to fetch the pins from given board but when it returns the json there is no image link, the image field return as null. So how to get image with oin content. Here is json retrieved.
Array ( [data] => Array ( [0] => Array ( [id] => 400327854358866609 [link] => https://www.pinterest.com/r/pin/400327854358866609/4837342446222323658/8737cad9ec4b46439289fbd4f22353f02255549d33a8999691d82b8642f42625 [url] => https://www.pinterest.com/pin/400327854358866609/ [creator] => [board] => [created_at] => [note] => Hello this is simple test [color] => [counts] => [media] => [attribution] => [image] => [metadata] => [original_link] => ) [1] => Array ( [id] => 400327854358814014 [link] => https://www.pinterest.com/r/pin/400327854358814014/4837342446222323658/3f1103b8d1c97de21f913293ee6062f4122313c931b054764167e96745f64465 [url] => https://www.pinterest.com/pin/400327854358814014/ [creator] => [board] => [created_at] => [note] => 55 Awesome Men’s Tattoos | InkDoneRight We’ve collected 55 Awesome Different Mens Tattoo Designs to inspire you! We also have the meaning and symbolism behind the common men’s tattoo designs... [color] => [counts] => [media] => [attribution] => [image] => [metadata] => [original_link] => ) ) [page] => )
In above json image or media key has no values.
If you use the "API explorer", and add the "image" field, one of the outputs is the URL of the original image.
https://api.pinterest.com/v1/boards/BOARD_OWNER/BOARD_NAME/pins/?access_token=MY_TOKEN&fields=id%2Clink%2Cnote%2Curl%2Cattribution%2Cboard%2Ccolor%2Ccreated_at%2Ccreator%2Cimage%2Cmedia%2Cmetadata%2Coriginal_link%2Ccounts
Or using the JS SDK eg:
PDK.request(thisRequest, {fields: 'id,note,link,url,image'}, thisCmd,
function( PDKdata){};
See my example here:
Example of using Pinterest API
am unable to use the path returned by drupal 7 for an image which was uploaded for custom content type. the path returned is as follow:
Array ( [und] => Array ( [0] => Array ( [fid] => 6 [alt] => [title] => [width] => 464 [height] => 261 [uid] => 1 [filename] => _71135631_c0166859-snotty_child_with_a_cold-spl.jpg [uri] => public://_71135631_c0166859-snotty_child_with_a_cold-spl.jpg [filemime] => image/jpeg [filesize] => 22168 [status] => 1 [timestamp] => 1384797114 [rdf_mapping] => Array ( ) ) ) )
but when using the vale of uri, the image is not shown.
any assistance appreciated.
regards,
a.ali
Such uri-fields in Drupal always refer to the internal data-storage logic, hence the public:// at the beginning. Drupal uses Image Styles for any images attached to content.
To retrieve the full URL for an image, you should use image_style_url():
$imgPath = image_style_url('default', $object['und'][0]['uri']);
I am working with the Yahoo BOSS API to build an image search for motherpipe.co.uk.
I have managed to create a valid request for image listings and have received the response. My problem is that I don't understand how I can use the different elements of that response to build my nice-looking page of image listings.
Ideally I want to loop through the array and display a thumbnail and link for each item in the list but somehow I can't abstract the relevant bits from the $results.
The (example) output from the query with two listings is in this $results:
stdClass Object ( [bossresponse] => stdClass Object ( [responsecode] => 200 [images] => stdClass Object ( [start] => 0 [count] => 2 [totalresults] => 107000 [results] => Array ( [0] => stdClass Object ( [clickurl] => htt://library.thinkquest.org/07aug/01105/Sweden/stockholm.jpg [size] => 191.8KB [format] => jpeg [height] => 586 [refererclickurl] => htt://library.thinkquest.org/07aug/01105/Sweden/sweden_home.html [refererurl] => htt://library.thinkquest.org/07aug/01105/Sweden/sweden_home.html [title] => Stockholm is a beautiful city with Lake Mälaren on it’s WestSide ... [url] => http://library.thinkquest.org/07aug/01105/Sweden/stockholm.jpg [width] => 793 [thumbnailheight] => 118 [thumbnailurl] => htt://ts4.mm.bing.net/th?id=H.4970051277687231&pid=15.1&H=118&W=160 [thumbnailwidth] => 160 ) [1] => stdClass Object ( [clickurl] => http://summerventures.files.wordpress.com/2012/01/429c_stockholm_ch.jpg [size] => 2.3MB [format] => jpeg [height] => 1272 [refererclickurl] => htt://summerventures.wordpress.com/tag/stockholm/ [refererurl] => htt://summerventures.wordpress.com/tag/stockholm/ [title] => stockholm | Summer adventures [url] => htt://summerventures.files.wordpress.com/2012/01/429c_stockholm_ch.jpg [width] => 1800 [thumbnailheight] => 113 [thumbnailurl] => htt://ts2.mm.bing.net/th?id=H.4581116279128437&pid=15.1&H=113&W=160 [thumbnailwidth] => 160 ) ) ) ) )
Question:
What approach can I use to simply display a thumbnail picture with a link from each of the listings in this array, using the info in [thumbnailurl] and [refererclickurl] kind of like
<div> <<a href="[refererclickurl]"><img src="[thumbnailurl]" alt="alt text" /> </div>
I think I need a for each approach but after having tried for three days I can't make it work.
Any help much appreciated.
Try the following. The quoted object in your question is in the $o variable.
$html = '';
$images = $o->bossresponse->images->results;
foreach ($images as $image) {
$html .= "<a href='{$image->refererclickurl}'><img src='{$image->thumbnailurl}'></a>";
}
echo $html;
Note that if $obj->prop equals 'foo' then "{$obj->prop} is not bar" would equal 'foo is not bar'.
Its also good to note that the html would be better if you also output the image dimensions and may change depending on what html spec you're implementing.
so heres my predicament.
Currently using Yahoo API with PHP in order to use a 'Login with Yahoo' Function on my site.
I have managed to retrieve my entire profile. Trouble is, I can't directly display the primary email associated with the account.
If I use print_r($profile) I get everything dumped from my profile. It looks like this (personal data removed):
stdClass Object ( [uri] => http://social.yahooapis.com/v1/user/*********/profile [guid] => ***** [birthdate] => / [created] => 2010-04-22T20:47:48Z [emails] => Array ( [0] => stdClass Object ( [handle] => **#gmail.com [id] => 1 [type] => HOME ) [1] => stdClass Object ( [handle] => ****#yahoo.com [id] => 2 [primary] => 1 [type] => HOME ) ) [familyName] => Surname [gender] => M [givenName] => Ricki [image] => stdClass Object ( [height] => 192 [imageUrl] => http://l.yimg.com/dh/ap/social/profile/profile_b192.png [size] => 192x192 [width] => 192 ) [lang] => en-US [memberSince] => 2010-04-08T11:22:56Z [nickname] => Ricki [profileUrl] => http://profile.yahoo.com/*********** [updated] => 2013-03-03T18:12:22Z [isConnected] => )
Using $profile->emails->handle yields nothing however. Any ideas on what to do? I can use $profile->emails which returns an Array, displayed simply as 'Array' but if i try to select from the array i get an error:
"Catchable fatal error: Object of class stdClass could not be converted to string"
Anyone?
$profile->emails[0]->handle will give you the first handle in the system.
You can also do foreach($profile->emails as $email) { print $email->handle; }
For the life of me I can not figure out how to access the values of this array. Every example the stdClass Object has some type of value. If I try for example $obj->0->0->city; I get an error.
Can someone show me a example how to access [city] => toronto or even [date_created] => 2011-05-03 14:33:58?
I also tried this with no luck.
$object = $buy[1];
$title = $object->title[0];
echo "$title";
Thanks
This is what the api gives me.
stdClass Object
(
[id] => 1
[name] => toronto
[date_modified] => 2011-03-08 13:07:10
[tax_rate_provincial] =>
)
<br/>
Array
(
[0] => stdClass Object
(
[0] => stdClass Object
(
[id] => 28131844
[full_date] => 20110506
[end_date] => 20110511
[city] => toronto
[saved] => 1651
[discount_percentage] => 52
[deal_option] => Array
(
[0] => stdClass Object
(
[id] => 2600
[title] =>
[date_modified] => 0000-00-00 00:00:00
[date_created] => 2011-05-03 14:33:58
[value] => 3150
[price] => 1499
[deal_id] => 28131844
[is_default] => 0
)
)
[options] =>
[option_quantity] =>
[option_remaining] =>
[purchase_limit] => 1
[gift_limit] => 0
There is a special evil syntax to bypass numeric object attributes:
print $obj->{'0'}->{'0'}->city;
Is the correct syntax, and equivalent to the path you already determined.
Your second example is an array however, so it's probably:
print $array[0]->{'0'}->city;
The alternative is always to just foreach over a specific level - that works for objects and arrays likewise.