I'm trying to get the location of Instagram pictures from my account. The API is giving me all sorts of information about my account and pictures, but when I try to get the location of my pictures it says:
Trying to get property of non-object in ....
My code looks like this:
foreach($phplijst->data as $data){
echo "<img src=" . $data->images->low_resolution->url . " />";
echo "<p>" . $data->location->longitude . "</p>";
}
The first "echo" gives me all the images from my account. The second "echo" is supposed to give me the longitude of all the images on my account. Instead it gives me that error message. Does anyone know how to fix this?
It means that $data->location isn't an object.
You should check your object structure with var_dump($data) and verify it has the layout you expect.
Never mind guys! I've fixed it.
I forgot to add a location to my images so that's why I didn't get a location :)
Thanks for the help anyway!
Related
I am trying to use a twitter API to display the latest tweets in an area. the code sort of works and shows the message, timestamp when the tweet was posted and what was used to make it. however, I want to show the profile images and usernames of the people that posted them. but I keep getting the following error for both name and profile image:
Notice: Undefined index: get_tweets.php on line 40
here is the link for the web page that requests the tweets:
https://dl.dropboxusercontent.com/u/22591742/get_tweets.php
and the link to the API that I'm using:
https://dl.dropboxusercontent.com/u/22591742/TwitterAPIExchange.php
thanks in advance!
-Filip
Some of the properties you're trying to access are nested within the user array.
So profile_image_url and name are both within the user array.
You should reference them like so:
$status["user"]["profile_image_url"]
So for the line of your code where you're outputting the details from $status
echo("<p>". $status["user"]["profile_image_url"] . $status["user"]["name"] . "<b>Created at: </b>". $status["created_at"] . "<br/>". $status["source"] . "<br/>" . $status["text"] . "</p>");
I asked the same question earlier and it got down voted and I have no idea why. I'm building a class that outputs a news feed, but it's a very structured html that I'm going to use a lot on the site (hundreds of times), so I'm using a class method to display the feed html and everything. And I just echo the whole thing.
The method is set up this way:
private function feed ($var)
{
$Statement = $this->Database->prepare("SELECT * FROM feed WHERE col = ? ORDER BY timestamp DESC LIMIT 50");
$Statement->execute(array($var));
while ($row = $Statement->fetch(PDO::FETCH_ASSOC))
{
echo ' <div class="feed-box">
' . /*facebook name retrieved from the facebook */ . '
' . $row["post"] . '
<br/>
</div>';
}
} //end feed
The class is set up so that another method that has more of the html template calls this feed method. (I'm not trying to be too redundant here, but again the last time I asked this question it got down voted). So I'm pretty new to oop, and I'm looking to display the profile pictures of people who are logged in with facebook. This isn't necessarily a facebook question because I know how to do it normally, but I don't know how to get the facebook information within the class scope using just their id. Normally I;d get their picture by going linking to this url https://graph.facebook.com//picture. How do I do this within the class when I only sotre their facebook id in the database? I've been working on this problem for a couple days now, and I can't figure it out on my own. So I really appreciate your help.
It's getting to the point where I just want to statically type everything out because I know I could easily do that, but I'd really love to learn what the proper way is, especially since editing so many of these little boxes if I want to change something one day would be a real hassle. Thanks for your help. I really appreciate it. Let me know if anything is unclear I'll update the questino as soon as I can.
How do I do this within the class when I only sotre their facebook id in the database
echo '<img src="https://graph.facebook.com/' . $row['facebook_id'] . '/picture" />' ;
You say you only store the facebook id in your database. That is all you need to display the picture. Just append /picture to the user's FB graph link to get the picture.
I have any adress recorded in my databse corresponding to the customers.
The trouble I met is concerning the including of a googlemap.
I have the following code that convert an adress to the polares.
function getCoordonnees($adresse) {
$url = "http://maps.google.com/maps/geo?q=" . urlencode($adresse) .
"&output=csv";
$csv = file($url);
$donnees = preg_split("#,#", $csv[0]);
return $donnees[2] . "," . $donnees[3];
}
The following code returns to me somethinbg like that
48.9381235,2.1329083
When I use the google map I have a picture like that :
Which comes from this url (generated by my function
http://maps.google.com/staticmap?center=48.9381235,2.1329083&zoom=15&size=300x300&maptype=mobile&markers=48.9381235,2.1329083,red&key=***********************KEY*GOOGLEMAP************&sensor=false
When I try to display that picture in my website, An error appears,
<img src="http://maps.google.com/staticmap?center=<?php echo $polar; ?>&zoom=15&size=300x300&maptype=mobile&markers=<?php echo $polar; ?>,red&key=***********************KEY*GOOGLEMAP************&sensor=false" style="border:double 2px" />
Where $polar is the polares.
Including this code in my website returns to me the following mistake :
Failed to load resource: the server responded with a status of 403 (Forbidden)
I have no idea from where comes this error. Actualy I do not think it comes from google map because on stackoverflow, the picture is displayed.
So I would ask if anybody know where can comes this mistake ? Is is from the server configuration or something else ? I've been looking for that since many times without answer.
Anykind of help will be much appreciated.
I was having the same issue and I decided to turn on Google Maps API v2
I already had Google Maps API v3 on but before messing with to many settings I turned them both on.
Now it works
I want to include a file, based on a value I get from my database. Inside class page in page.php I have this function to get the data I want :
function getPage(){
$page=array(
'title'=>$this->title,
'content'=>$this->content,
'module'=>$this->module
);
return $page;
}
And in pageview.php I call it like this : $elements=$page->getPage();
The function works just fine and I get my content , which I can manipulate like this for example(I know heredox is not the way to go but please ignore it, it's not the problem) :
echo <<<EOT
<div class='row-fluid'>
<H1> title:$elements[title]</H1></br>
$elements[content]
$elements[module]
</div>
EOT;
Now here comes the problem. I have a function called includeModule, which is like this :
function includeModule($page){
$page=strtolower($page);
if(file_exists("modules/".$page."php")) include("/modules/".$page."php");
else Echo "No such Module Exists :".$page." </br>";
}
Now lets say I want to include a page named "tax.php". If I use include("/modules/tax.php)"; it works just fine. If I try though to use include("/modules/".$elements[module].".php)"; it does nothing ( an yes $elements[module] does contain only the word "tax" ).
I even tried assigning the value of $elements[module] to another variable but nothing.
The strangest part of all is that if I try to use my function ( includeModule), even if I manually set the $page variable to "tax", it still doe not include anything and says that the file does not exist ( even though it does) ?
Any help on this ?
edit: i already tried removing the / but if i do it includes nothing again
edit: i've change the function a litle so i can get some feedback
if(file_exists("modules/".$page.".php")){
echo "<p>file exists</p>";
include("modules/".$page."**.**php");
}else{
echo getcwd();
Echo "<p>No such Module Exists :".$page."</p>";
}
OK solved. thanks for all the answers. By my mistake the trailing slash as well as the dot right before the php extension were left out . thanks for helping :)
if i use include("modules/tax.php)"; it works just fine.
In your code, you're using
include("/modules/".$page."php");
^-- Note the leading /
Try removing the /
You are seeing if "modules/".$page."php" exists but trying to include "/modules/".$page."php" which are probably not the same things (notice the leading / on the latter).
if(file_exists("modules/".$page."php")) include("modules/".$page."php");
OK ive solved it thanks guys:) each answer was helpfull :) ( the answer was a combination of your answers+a litle more atttention needed from me . I forgot the . right before the php extension .. lolz.. guess when you are tired you have to take a litle break off word in order to be able to concetrate right ). thanks again guys :)
Been at this for a while and cant figure it out so i thought id come to the ppl who know.
my php / sql is so-so but.....this is what im trying to do / figure out..
i have a database setup to take in messages (of any sort) and works fine. The user enters data in a field, hits send, and the message gets logged.
But when a user puts in a link for example " http://www.google.com "
its stored in the DB just fine but when its printed back onto the page, it comes back as plain
text, what i want is that when the page throws back the message with the link in it, that the link is live and clickable.
Ive googled my a$# off but im guessing im searching for the wrong thing (or im missing something unbeknownst to me. )
Any tips/*direction* etc, ill gladly accept. also, I dont mind doing the work/research so if you have links only ill take those too.
Thanks in advanced.
You need to parse messages plain text in order to find links. Then, change link texts by adding an anchor tag (<a>).
This link should help you.
you need regular expressions to detect links and convert them to ...
see the answer here:
PHP validation/regex for URL
<?php echo "your_field"; ?>
Something like this should work (I took this from some code I wrote for a client):
$query = mysql_query("SELECT * FROM wcordersinfo WHERE dealer_id = '" . $dealer_id . "' && drawing_num = " . $_GET['reference_id'] . "");
while ($orders = mysql_fetch_array($query)) {
if ($orders['drawing_num'] != '') {
$link_open = '<a href="http://www.example.com/dealers/order-details.php?reference_id=' . $orders['drawing_num'] . '">';
$link_close = '</a>';
} else {
$link_open = $link_close = '';
}
and then where you want to display the content:
<?php echo "<li>' . $link_start . $orders['carrier'] . $link_end . '</li>"; ?>
You may want to check out http://www.php.net/manual/en/function.preg-replace.php for replacing regular expressions with something.
There you want to replace every website with a typical html link syntax like ...