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.
Related
I have some videos uploaded on viddler, now need the raw file/video link in mp4 format so i send it as a json rest API request to the android app,at the moment I can get the html links to it but I need this too, is such a thing possible? My website is in word press, and I am using the Viddler WordPress plugin.
After my wrong comment, A quick look at there API documentation. I think you would use viddler.videos.getDetails and after json_decode()'ing it access the value as:
$resp->video->url
or
$resp->video->html5_video_source
Which would be a url like:
http://www.viddler.com/file/VIDEO_KEY/html5
Or whichever one returns something like the following is what your after: (Note: I dont use there API, and it doesn't show the format of the url in the documentation):
http://www.viddler.com/file/d/48eaa1ff.mp4
Also there is a Viddler PHP Wrapper that might make it easyier for you then writing your own wrapper for there API.
Edit see comment,
By you supplying the link to the video, I can deduce my answer to:
Its not a direct link to the file; a9fcd88d is the id for that video. Your need to use that id as the video_id parameter, in the following API request (viddler.videos.getDetails):
GET /api/v2/viddler.videos.getDetails.php?sessionid=SESSIONID&key=YOUR_API_KEY&video_id=a9fcd88d
Its all in the docs link above, see click this link (notice the id) http://www.viddler.com/file/a9fcd88d/html5 your see its webm type or HTML5 fallback video.
But, your after .mp4 version which is not offered as std, so your need to use that id(a9fcd88d) to get the mp4 version from that API result set, which I don't know the result of $resp->video->url response, because its not in the docs, else it would be easy to just parse the id and download in mp4 format.
Also they make a futile attempt to make it secure by the player being built through an iframe with javascript, obfuscation and a XSRF token but with some simple console and breakpoints its trivial to get to the actual path of the video and download it (fail...):
http://mynivo-vfs.cdn-ec.viddler.com/mynivo_1s219veo8r3sp77i3oaz90bwhjar3c.mp4?fd9f2a1c14aadf1069f046c16bf41e2b3776a6b320734cdc73d93c30ad8d0e26c7fa5d6ea6105bad4ec694d7af6126c6df817ecdfe80910ce08b938b90e4efc7de19e2b64be6fbfaa9ab32e29b3f
How long that key parameter stays active I dont know... (edit) actually couple of minutes later its now the following, so it is time based.
http://mynivo-vfs.cdn-ec.viddler.com/mynivo_1s219veo8r3sp77i3oaz90bwhjar3c.mp4?fd9f2a1c14aadf1069f046c16bf41e2b3776a6b320734cdc73d93c30ad8d0d2bf4206bd54f270ce83a6237e126803d96b8d90f53e539676c7518df3e497affdd3018bb2c364035984d1b934be221
Hope it helps, basically use the API to get the unsecured mp4 version url, which I presume will be in $resp->video->url
Edit 2
But unless you want to download the video, you might as well use the provided embed code link in an iframe, for example.
<?php
$video_id = 'a9fcd88d';
echo '<iframe width="100%"
height="100%"
src="http://www.viddler.com/embed/'.$video_id.'"></iframe>';
?>
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())
I am using php to develop a twitter search api which is able to search twitter, and save posted images from tweets.
It all works fine etc, but for facebook, instead of the image being loaded with the webpage, its loaded after in a response. Using firebug, going to the Net tag, I can see the html source code I need under the response tab for a getphoto(). I am looking to grab an img src from this html text, but
Facebook seems to load the basic stucture, then reload the page with the image on it.
My question is: How can I get this 'response body'?
I have used get_headers() before, but I dont think it will work in this situation, and I have trawlled the net looking for an answer to this, but none have appeared.
Any help would be much appreciated, thx in adv.
Dont think my code will help explaining, but willing to put some up
EDIT:
example facebook url: /https://www.facebook.com/photo.php?pid=1258064&l=acb54aab14&id=110298935669685
that would take you to the page containing the image
This is the image tag:
img class="fbPhotoImage img" id="fbPhotoImage" src="https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash3/522357_398602740172635_110298935669685_1258064_1425533517_n.jpg" alt=""
But this does not show up until the response comes through.
I have a get_header funciton in to expand shortened URL's, due to twitters love for them, and this can get and image from other 3rd party photo sites with multiple shortens/redirects.
Have not used cURL before, is it the best/only way?
Thanks again
instead of the image being loaded with the webpage, its loaded after in a response
I don't know what this means.
I can only guess that the URL you are trying to fetch the html from, which your code is expected to parse to extract an image URL, is actually issuing a redirect.
Use curl for your transfers and tell it to follow redirects - NB this will only work with header redirects - not meta equiv redirects, meta refresh redirects nor javascript location redirects.
(maybe Faceboo0k don't want you to leech their content?)
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.
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.