Getting different feeds from one URL - php

i am trying to get some data(stats) from a specific YouTube channel. For this i am using following URL:
https://gdata.youtube.com/feeds/api/channels/rX3yH7nFEQq49lQGVk2Iqg?v=2
When i enter this URL directly into FireFox Addressbar i get the result i am looking for. BUT
if i open the exact same URL with:
$data = simplexml_load_file('https://gdata.youtube.com/feeds/api/channels/rX3yH7nFEQq49lQGVk2Iqg?v=2');
i get a completly different result(using print_r($data))!
Is there an explanation for this? Are i am doing something wrong? Is there something missing?
Thank you!

The most useful information about a channel will actually come from the /users/ service, not the /channels/.
You could also add in alt=json, unless you really like parsing XML instead of working with JSON.
Finally, the "correct" form for a channel id has a UC prefix, though v2 supports channel ids without the prefix as well.
Putting that all together gives you https://gdata.youtube.com/feeds/api/users/UCrX3yH7nFEQq49lQGVk2Iqg?v=2&alt=json
(leave out alt=json to work with simplexml_load_file())

Related

Pass php results to another website.

So what I am trying to do is this:
On my server users can put there YouTube channel name. My php file will then parse the channel and output HTML code with results. What I am looking to do is for the users to be able to put a code on there website that till call on my website lets say youtubevideos.com/videos.php?channel=channelname my code will take that name and output the videos back to there site. much like Google ads I guess.
Any idea how that is done, other than an iframe, I figured that will be my last resort.
I think what I'm looking for if for them to put a JavaScript on there site that will render as the HTML code I'm pushing from my php file.
Thank you!
The receiver code which is on the server you target need to set a header like that :
"Access-Control-Allow-Origin:*"
So, if you provide a service which need to exchange with your server & your code, is it possible. If you can't edit the targeted code & the header is not setted, it'll be impossible
There would be two parts of this solution.
In the videos.php file on your server, you would implement the logic to scrape the data from the original site and format it in the way you want to show on the final website.
For the end user, you would give a code similar to this that they would have to paste in their php pages to display the content from your site.
$your_website_url="http://youtubevideos.com/videos.php?channel=channelname";
//Don't forget the http:// at the start.
echo file_get_contents($your_website_url);
If file_get_contents() gives a security error, you can use curl.
I hope that helps.

How to get image url from tweet text in php?

I'm currently displaying pics in my app from twitter's default image service since they get included in the json response but I'd like to try to get images from yfrog, twitpic, lockerz or similar providers.
I'm using the rest api so I was thinking about adding filter:links to the search query, extract the url from the tweet and check if the link is an image but I'm not sure exactly how to get the url since I assume it'll require some regular expressions plus most of the tweets url are shortened versions that redirect to the actual photo somewhere so I believe this could be a problem. It'd be nice if I could verify that the url contains any of the image providers mentioned above too (kind of like a first filter before checking if the url is an image)
Could someone point me in the right direction? Thanks in advance!
For detecting the links, just google for a regex to match a url. Like this here:
http://snipplr.com/view/2371/ or http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers
and cycle through the matches array:
http://php.net/manual/en/function.preg-match.php
This one should solve the short links problem (assuming you have curl installed): follow redirects with curl in php
Use this here to check if the link is an image:
http://php.net/manual/en/function.get-headers.php (parse "Content-Type" for "image")
I hope this helps.

Trying to find a "backdoor" to the number of shares/+1's/stumbles a website has

I need to access the number of facebook shares, google +1's, stumbles for a given website. My first thought was to use file_get_contents on the url of the button alone, removing everything but the number but in hindsight, the number is gotten using javascript so I sanitized out the html and left the javascript. I've managed to find a url for twitter:
http://cdn.api.twitter.com/1/urls/count.json?url=[put encoded url here]
This returns a json object as follows:
{"count":52,"url":"[url here"}
I have gone over the code for the buttons for hours using firebug but I'm not that great at Javascript so sometimes I'm not even sure what I'm looking at. Anybody have any ideas at how I could accomplish this?
For facebook you can use the opengraph.
Example https://graph.facebook.com/cocacola
You can then extract all the info from the json object.

How to make this GET show the link url?

I have:
https://gdata.youtube.com/feeds/base/users/machinima/uploads?fields=item(title,pubDate)&orderby=updated&alt=rss&client=ytapi-youtube-rss-redirect&v=2
I would like this to show the link element of the RSS feed too.
Adding item(title,pubDate,link) does not seem to work.
What am I doing wrong?
EDIT: I would like this to only get title,pubDate,link and not the entire feed (for bandwith reasons), hence the problem. Sorry if that was not clear.
You have to replace the item(title,pubDate) part directly after the ?fields= key:
https://gdata.youtube.com/feeds/base/users/machinima/uploads?fields=item(title,pubDate,link)&orderby=updated&alt=rss&client=ytapi-youtube-rss-redirect&v=2
--------------------------------------------------------------------^

Flickr API - Latest Photos from a Set?

I'm currently using this JSON to get the latest flickr photos of an ID:
http://api.flickr.com/services/feeds/photos_public.gne?id=49107890#N06&tagmode=any&format=json&jsoncallback=?
Now I need to change my code to display a set instead of an ID. I can get some JSON return with this:
http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=3bfff97a6e1eb0b1a0a7d460c780e273&photoset_id=72157623801339634&per_page=6&format=json
But there are no source URLs? I'm hoping someone with a little more flickr API experience than I can help out. I simply need to supply a Set ID and for it to return the latest 6 thumbnails.
You can construct the URLs yourself using the guide here: http://www.flickr.com/services/api/misc.urls.html
All the information needed is returned in the JSON response:
http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg
or
http://farm{farm-id}.static.flickr.com/{server-id}/{id}{secret}[mstb].jpg
or
http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{o-secret}_o.(jpg|gif|png)
As phidah pointed out, you can easily construct the URL from the returned data. However, there's a much easier method that just requires adding an extra parameter to your REST request. Just append &extras=url_sqor you can use any of the following, depending on which URL you want:
url_sq : Small Square
url_t : Thumbnail
url_s : Small
url_m : Medium
url_o : Original (requires special handling)
And you'll get an extra field in your JSON response that contains the URL. Easier in my opinion. :)
Check here for a full list of fields you can add.

Categories