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>");
Related
I'm using the Facebook Comments plugin (from FB, not a WP Plugin) on my WP site.
I want to get the number of comments for a specific URL, so I can set it up to say "start the conversation" or "join the conversation"
I've done my research and found several variations on the code below posted as recently as April of this year:
$rest_url = "http://api.facebook.com/restserver.php?format=json&method=links.getStats&urls=https://my.com/".$my_slug;
$json = json_decode(file_get_contents($rest_url), true);
// echo "Facebook Shares = " . #$json[0]['share_count'];
// echo "Facebook Likes = " . #$json[0]['like_count'];
echo "Facebook Comments = " . #$json[0]['comment_count'];
However, after some frustration, I realized I needed to dump $json and see what's in there:
var_dump($json);
and to just parse out the important part, there was a message inside:
"REST API is deprecated for versions v2.1 and higher (12)"
There's a lot I don't understand about APIs and Facebook's system.
But... can you tell me what the current way of getting the comment count is now? I just need it in a variable and I can go from there.
Thanks for any help!
Chris
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!
google login
I am working on php . I have made app on Google . If u can see my link , I am using state parameter , in which state=reg . In my callback page , I am trying to get this value ie $_get['state'] but its not showing me anything . Am i doing the right way ?
I've never seen a Client ID that begins "**", but in your link I see client_id=%2a%2a43760%2a%2a%2a%2a%2a-cp7 which really looks wonky. Are you sure that’s right?
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 was wondering if it was possible to use PHP / AJAX to have a string of text sharable to Facebook? For example, I use PHP to return an SQL query, then use that same string of text in correspondence with a button, to share to my Facebook wall. So, it might look something like this in the PHP:
while($note_row = mysql_fetch_row($result)) {
echo '<p> "' . $note_row['my_note_text'] . ' "</p>';
echo '<input type="button" id="' . $note_row['my_note_id'] . '" class="share-to-facebook" value="share" />';
}
If anyone has some advice whether this is possible I'd be super happy. I also apologise if my PHP is wrong, I haven't checked it.
You have some options:
sharer.php
https://www.facebook.com/note.php?note_id=407822831963
Create a share link. You can set title and url.
Feed Dialog
https://developers.facebook.com/docs/reference/dialogs/feed/
Creates a share dialog. More options for description and image etc. Might be a replacement for sharer.php.
If you need to post to the wall from your app, you need the get permissions by having the user accept your app to Facebook. Read more about authentication at https://developers.facebook.com/docs/authentication/