I know you can use the API (https://dev.twitter.com/docs/api/1/get/users/show), But how can I get this to appear on my website? E.g. 'Username' has 'follower count'.
Here you go:
<?php
$url = "http://api.twitter.com/1/users/show.json?screen_name=jjmpsp&include_entities=true";
$feed = file_get_contents($url);
$twitter_decoded = json_decode($feed);
echo $twitter_decoded->followers_count;
?>
Related
I am trying to extract the video link of my private playlist. but i am unable to do
I used the below code to get the list
<?php
if(isset($_POST['send']))
{
$cont = json_decode(file_get_contents('http://gdata.youtube.com/feeds/api/playlists/'.$_POST['a'].'/?v=2')); ?>
<?php $feed = $cont->feed->entry; ?>
<?php if(count($feed)): foreach($feed as $item): // youtube start ?>
<?php echo $item->{'media$group'}->{'yt$videoid'}->{'$t'} ?>
<?php echo $item->title->{'$t'} ?>
<?php endforeach; endif; }?>
but this doesn't work. i need to extract only link with video title.
i have my account details with me how its possible using php
Since you want a private playlist, this will need to be an authenticated call, so you'll first have to set up an oAuth exchange. In PHP the easiest way to do this is with the gapi client; you can see more info (and get the library and sample code) here:
https://developers.google.com/youtube/v3/code_samples/php#retrieve_my_uploads
It will require you to use the client ID and secret for your registered app, though (don't forget to turn on the YouTube API v3 in the registered app!).
Once the oAuth is working, you can change the sample code listed above to very easily get your private playlist; starting with line 40, you'll have to use a call that's something like this:
$playlistResponse = $youtube->playlist->listPlaylists('contentDetails', array(
'id' => $_POST['a'], // assuming this variable represents the id of your playlist
));
You'll also have to somewhat modify the code after that block to be able to parse the playlist feed and get your info.
I am working on pulling the number of twitter followers into my Wordpress page but running into a small problem I cannot figure out. I imagine it would be a quick fix...do you think you can help?
The issue is the output reads:
11131
I would like it to read:
11,131
You see the comma in the correct position...not sure how to get that to render in the right format. Here is the code I am working with:
<?php
$data = json_decode(file_get_contents('https://api.twitter.com/1/user/lookup.json?screen_name=erinschreyer'), true);
echo $data[0]['followers_count'];
?>
Any help is appreciated...
It would work with that:
<?php
$data = json_decode(file_get_contents('https://api.twitter.com/1/users/lookup.json?screen_name=erinschreyer'), true);
$followers = $data[0]['followers_count'];
echo number_format($followers);
?>
See number_format()
ich want to code a site with informations about some youtube-channels. I got the following parameters:
Subscribers:
<?php
$json = file_get_contents("http://gdata.youtube.com/feeds/api/users/*username*?alt=json");
$data = json_decode($json, true);
echo '' . $data['entry']['yt$statistics']['subscriberCount'];
?>
Chanel-Views:
<?php
$json = file_get_contents("http://gdata.youtube.com/feeds/api/users/*username*?alt=json");
$data = json_decode($json, true);
echo '' . $data['entry']['yt$statistics']['viewCount'];
?>
Total-Views:
<?php
$json = file_get_contents("http://gdata.youtube.com/feeds/api/users/*username*?alt=json");
$data = json_decode($json, true);
echo '' . $data['entry']['yt$statistics']['totalUploadViews'];
?>
But how could I get the count of the uploaded Videos. I only want to show the count how many videos were uploaded by this user.
And i want to show the age, description, snippet, the date when he joined youtube.
Could anybody help me?
The number of public videos in a given YouTube channel can be obtained via the openSearch$totalResults->$t property of the uploads feed for that channel. Here's an example for GoogleDevelopers:
http://gdata.youtube.com/feeds/api/users/googledevelopers/uploads?v=2&alt=json
"openSearch$totalResults": {
"$t": 1458
}
Most of that other information you're looking for, regarding the channel creator's personal details, is no longer exposed on YouTube.com or via the API.
I am trying to write some code in php to show on a website exactly how many times a particular url has been tweeted on Twitter.
I assume I use the info in this page;
http://api.tweetmeme.com/url_info?url=http://dori.co.nz/
But what code would I need to add to the header of a Wordpress theme to call those values?
Many thanks in advance!
<?php
$url = "http://api.tweetmeme.com/url_info?url=http://dori.co.nz/";
$test = file_get_contents($url);
$xml = simplexml_load_string($test);
echo $xml->story->url_count;
?>
Here we go.
I'm using the Twitter-generated "Twitter Badge" HTML and JavaScript to show my Twitter feed on a web page. I'd like to include the replies to me in the same feed, or at least in another one. (My replies to others are already in there.) One the Twitter site, I just click on the #username link on the right panel and get the #replies for my userid. Does anybody know how to embed that in a page? Thanks.
There's an API method that will let you pull the 20 most recent #replies in XML or JSON format; however, it requires authentication, so you'll want to do this on the backend. (There are OAuth libraries for Javascript, but that doesn't sound especially workable to me for this use case.)
The reply link suggested by #Meredith is removed from twitter. Anyone else have a better solution ?
As long as you use twitter regularly enough to have tweets in search(expires after sometime), you could use twitter searches jsonp.
I wrote a simple js lib around it. http://gist.github.com/110884
That will give you an array of matching tweets that you can then style or whatever.
//done up in no framework js
Twitter.search({q:"alan",
callback:function(results){
var body = document.getElementsByTagName("body")[0];
for(var i=0;i<results.length;i++)
{
alert(results[i].text)
}
}
})
Have you considered using Juitter - jQuery Plugin for Twitter?
An easy way to embed any content from an external page (including tweets) is to use the following code:
<?php
echo "<html><head>";
echo "<style> body { background: #FBFAF9; font-family: sans-serif; }";
echo "h4 {text-transform:capitalize; font-family: sans-serif;} h5 {text-transform:capitalize; font-family: sans-serif; color: grey; } </style>";
echo "</head><body>";
$data = file_get_contents('https://twitter.com/your_feed_here');
$data = explode("<div class=\"stream profile-stream\">", $data);
$data = explode("<div class=\"grid hidden\">", $data[1]);
$data = str_replace("</p>", "</p>", $data[0]);
$data = explode("\n", $data);
foreach ($data as $line) {
$date = explode("data-long-form=\"true\">", $line);
$date = explode("</span>", $date[1]);
$article['date'] = $date[0];
$title = explode("<p class=\"js-tweet-text tweet-text\">", $line);
$title = explode("</p>", $title[1]);
$article['title'] = $title[0];
$articles[] = $article;
}
unset($articles[0]);
unset($articles[count($articles)]);
foreach ($articles as $markup) :
?>
<div class="entry">
<h5><?=$markup['date'];?></h5>
<div style="width:270px"><?=$markup['title']?></div>
</div>
<?php endforeach; ?>