I've come to some problems. I've made a wordpress plugin, which automatically gets the most 20 recent Instagram posts and then, in theory, it should make me let to insert the newest image as a shortcode in to the post. Basically, I get an error message displaying:
Notice: Uninitialized string offset: 0 in D:\XEMP\htdocs\xd\wordpress\wp-content\plugins\insta-live\insta-live.php on line 29
Now, the code to reproduce this is:
//define Access token
$accesst= "PUT YOUR INSTAGRAM ACCESS TOKEN HERE";
//userid
$userid= YOUR INSTAGRAM USER ID HERE;
//image count to get
$count=20;
//get api contents
$content = file_get_contents('https://api.instagram.com/v1/users/self/media/recent/?access_token='.$accesst.'&count='.$count);
//converting JSON to object
$standardres = json_decode($content, true);
//array method
foreach($standardres['data'] as $photo) {
$imageData = base64_encode(file_get_contents($photo['images']['standard_resolution']['url']));
$images[] = '<img src="data:image/jpeg;base64,' . $imageData . '" />';
}
//create functions for shortcodes
function fone($images){
return $images[0]; //naudok tik [one]
}
//shortcodes
add_shortcode( 'one', 'fone');
?>
Any ideas how to solve this? A var_dump() gives me the images above the header..
Related
I have the following url:
https://blockchain.info/multiaddr?active=1AT4ES3ee1N6iBzzbdK8xvcAV3CBTRKcbS|1FHcYth4LRJMwNx2y8NR5DH7sYCiVzXs3Y&n=1
I want to access the final_balance from the output of the url.
I have the following code:
$value = file_get_contents($url);
$FinalBalance = $value["final_balance"];
var_dump($FinalBalance);
Error PHP Warning: Illegal string offset 'final_balance'
I also tried the following code:
$value = file_get_contents($url);
$json = json_decode($value);
var_dump($json);
$FinalBalance = $json["final_balance"];
var_dump($Final_Balance);
Error PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array
Your are near to finish that stuff but I will write down desired solution. Please have a look.
$url="https://blockchain.info/multiaddr?active=1AT4ES3ee1N6iBzzbdK8xvcAV3CBTRKcbS|1FHcYth4LRJMwNx2y8NR5DH7sYCiVzXs3Y&n=1";
$value = file_get_contents($url);
$FinalBalance = $value;
$data=json_decode($FinalBalance);
echo $data->wallet->final_balance;
echo $data->addresses[0]->final_balance;
echo $data->addresses[1]->final_balance;
exit;
You are going to access the inner object so you have to provide proper reference whether it is an array or an object.
I am trying to fetch the image which is already in parse database. In array I am getting the all the fetched data including the image URL but when I am trying to echo that particular URL it is echoing blank!!
Bellow is the code
$object = new ParseQuery("billComputing");
$getdata=$object->descending("updatedAt");
$results = $object->find();
$data=$results[0];
echo "<pre>";
print_r($results);
echo "signature".$sign=$data->get('Signature["url"]');
In print_r() - I am getting this
[Signature] => Parse\ParseFile Object
(
[name:Parse\ParseFile:private] => tfss-8a4dbd13-7e16-4efc-abcf-08e901924f49-sign
[url:Parse\ParseFile:private] => http://files.parsetfss.com/864d47af-9eac-4b75-ae30-17b7352d16ca/tfss-8a4dbd13-7e16-4efc-abcf-08e901924f49-sign
[data:Parse\ParseFile:private] =>
[mimeType:Parse\ParseFile:private] =>
)
I am not able to display the URL. Appreciate help in advance.
Try this :
$object = new ParseQuery("billComputing");
$getdata=$object->descending("updatedAt");
$results = $object->find();
$data=$results[0];
echo "<pre>";
print_r($results);
$file = $data->get('imageColumnName');
$imageURL = $file->getURL();
// you will get image url in $imageURL variable.
here is my function in a class called getminecraftprofile.php
basically it takes data from https://sessionserver.mojang.com/session/minecraft/profile/
dependant on the UUID of the user and gets an array that i can pick formation from.
the URL strings are base64 encoded so it decodes that as well.
public function getSkin()
{
$properties = $this->properties;
$encoded = json_encode($properties);
$imgUrl = json_decode(base64_decode(json_decode($encoded,true)[0]['value']),true) ['textures']['SKIN']['url'];
$img = file_get_contents($imgUrl);
echo($img);
}
this is the file that is passing in what user profile to find and get the skin of that profile. for most profiles it works perfectly and you can see it in action at http://jamesplanet.net/test/src/getskin.php?username=dinnerbone
<?php
include ($_SERVER["DOCUMENT_ROOT"] . '/test/src/getminecraftprofile.php' )?>
<?php
$profile = ProfileUtils::getProfile("useruser3");
//$result = $profile->getSkin();
$properties = $profile->getProperties();
$encoded = json_encode($properties);
$imgUrl = json_decode(base64_decode(json_decode($encoded,true)[0]['value']),true)['textures']['SKIN']['url'];
$img = file_get_contents($imgUrl);
var_dump($encoded);
echo('Texture URL Decoded: ' . $imgUrl );
it all grinds to a halt however if i say
$profile = ProfileUtils::getProfile("_jeb");
then it throws this at me
Warning: file_get_contents(): Filename cannot be empty in /Applications/AMPPS/www/test/src/getskin.php on line 10
string(908) "[{"name":"textures","value":"eyJ0aW1lc3RhbXAiOjE0MDM0ODE0Mjk2NDMsInByb2ZpbGVJZCI6IjdmM2ZjY2ZjYzUzOTQzNTdhZmEwMjExYTYyODc3MWU0IiwicHJvZmlsZU5hbWUiOiJfamViIiwiaXNQdWJsaWMiOnRydWUsInRleHR1cmVzIjp7fX0=","signature":"xIgM9w3MfZHMjlsZyrMDAF1CTAhhhhSWfjRqJgW3NNTCyotVkL9IMDN6ZzPIoNESFBlhwspxfKhrAC81+GlEUcFxLYilzO6qE+\/pYciNS78b9MxRK7R5xEoNNzFhXAyo9\/cW5X7V6bFxOB2MU9Fg7NXt\/B\/u4VypqGsbCA+OAm7Kgomlhkw3wkm1R1djfd5oBqwlCKhTWxt4k4mQJzThsqE5ffLdTcPeMoipezw4NHAV1QJfXZZlGsEDG\/KkzUDh6eOz+QufYvhcxGrOAfwJ4TzlLbu0QyT8IRIu0E5LY96sTSecWQ27W7TzsumXiXrkpOSLZrOi5yqGFMmfOEHqo8dLRnxhoNmyQpzN2rE4OvNBwKqvzOeRbigOzQSSg5xupydFFLdc20Pj9CXcTB18K12fXt6W8FJ+AzYUccPrSx\/1RJALkef9W5DCxNLOLLR5yIS8Irff3\/Gn2sRwTG8EXJz+6qRB50e02jdyTv9DZz853w+TAVoNtSkBB8W9aC08XUSCFFg1KAaLILkRi8H+76BE1pZKraPAoW8MpsUbd6J+6k0kU5lqdtiJZ1PtDssVMA+p9MwtOmQqD7n4hPXehULBv4+phQjZi37s1I6ZWYrQBE7raq3ZKfDx9ztccmHEyk\/VHSboo0QmtM8iCOCOC1l0Jv9QrV\/YQRZil03x+OQ="}]" Texture URL Decoded:
i know there is data there because its visible before the base64 decode.
where is it going wrong?
here is an example of what is being pars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SC6ivpDIDBQv3myBLNnHqE7/+Z8DGKa+Bf/nQW0sMdVsNFOxIeiXMyXpWAHMw3/Ee21aMWEUq+rD8l4CD2FTZkQ/gv18y3y7CR9fYIKU+EPccnDUtyF+Y257UtCUag7i0vlkiBpIh46jhpjIkhR+iAG4URqQA6I="}]}
I want to store session specific data in JSON format. I got this part working, but now I want to be able to append data to this file. This is currently a snippit of what I have:
$file = 'sessions/' . session_id() . '.json';
$current = json_decode(file_get_contents($file));
if (empty($isEnabled)) {
$output1 = array($urlStripped => '<img src="images/error.png" height=20 length=20>');
$output2 = $output1 + $current;
$contentToFile = json_encode($output2);
}
else {
$output3 = array($urlStripped => '<img src="images/vinkje.png" height=20 length=20>');
$output4 = $output3 + $current;
$contentToFile = json_encode($output4);
}
file_put_contents($file, $contentToFile);
header( 'Location: index.php' ) ;
But this is giving me this error: PHP Fatal error: Unsupported operand types in [..]. I think that $current is a dictonary, and I'm trying to add $output1 to it which is an array?
Maybe someone could give me some pointers?
json_decode decodes into an object, not an array. You can pass true as the second argument to use it as an array:
$current = json_decode(file_get_contents($file), true);
What you currently have tries to merge an array with an object, thus the unsupported operand type.
I would like to add a video to a playlist using GData. So I have no problem creating the playlist, but I can't manage to add a video to it.
Here's what I do:
$playlist = $yt->newPlaylistListEntry();
$playlist->summary = $yt->newDescription()->setText("test");
$playlist->title = $yt->newTitle()->setText("test2");
$postLocation = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
$yt->insertEntry($playlist, $postLocation);
$feedUrl = $playlist->getPlaylistVideoFeedUrl();
$videoEntryToAdd = $yt->getVideoEntry(..given id here..);
$newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM());
$yt->insertEntry($newPlaylistListEntry, $feedUrl);
And I get the following error:
Notice: Trying to get property of non-object in C:...\library\Zend\Gdata\YouTube\PlaylistListEntry.php on line 296
Which is caused by this code:
$feedUrl = $playlist->getPlaylistVideoFeedUrl();
var_dump shows that the $feed_url is NULL. And it shows that $playlist is an object Zend_Gdata_YouTube_PlaylistListEntry, so I can't understand why it writes "property of non-object".
It seems like it is some kind of a bug in the API. So I've made a little workaround. It may seem ugly, but I had no other ideas.
function grab_dump($var)
{
ob_start();
var_dump($var);
return ob_get_clean();
}
function getPlayListLink($playlist) {
$test = grab_dump($playlist);
$test = strstr($test, "http://gdata.youtube.com/feeds/api/playlists/");
return strstr($test, "' countHint='0'", TRUE);
}
function addVideosToPlaylist($videos_arr, $playlistEntry, $yt) {
$feedUrl = getPlayListLink($playlistEntry);
foreach($videos_arr as $video)
{
$videoEntryToAdd = $yt->getVideoEntry($video);
$newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM());
$yt->insertEntry($newPlaylistListEntry, $feedUrl);
}
}
And simply call it like that:
addVideosToPlaylist($vids_id, $playlist, $yt);