Flickr API - Latest Photos from a Set? - php

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.

Related

eBay PN-Link-Generator using eBay API

I just started using the eBay API, but couldn't find a way to accomplish my needs. Also this should be really simple normally.
I want to know if it is possible to pass just any eBay URL to the API (PHP) and get a new link with my affiliate-parameters added.
It should just work the same way like the Link Generator in the Partner-Network-Section on eBay.
For example:
www.ebay.de/some-ebay-url/
Should be turned into something like:
http://rover.ebay.com/rover/x/xxx-xxxxx-xxxxx-x/x?xxx=4&pub=[my_publisher_id]&toolid=10001&campid=[my_campaign_id]&customid=&mpre=http%3A%2F%2Fwww.ebay.de%2Fsome-ebay-url
Or is there a easy way to just add my Affiliate id to an ordinary link?
Thanks
There isn't an API call at eBay to do what you want, in part because you can do it yourself pretty easily. You kinda already did it yourself with your example - yes, it's that easy.
You basically use the Link Generator just once (or a few times, to get acquainted with things) to obtain the template of a rover link and select the Custom URL option, then you use that format with any eBay URL you like, making any required tweaks. Take the eBay URL you want, URL encode it, then insert it as the &mpre= parameter at the end of the affiliate/rover link. That's the gist of it.
Know that &pub= is optional and doesn't affect the tracking of your link. &campid= is the necessary tracking parameter.
The long numerals in the front of the rover link (Rotation/Placement ID) define what ePN program to attribute tracking to. You might need to parse your input URL to determine the eBay domain (eBay.com? eBay.de?) to decide which Rotation/Placement ID to use, although they may/should work for cross-site tracking if you desire.
I've documented all the Rotation IDs here on my site. Click the page title up top for the main site with more eBay technical info I've discovered over the years.

Wordpress WP-API get images attached to post

so I am trying to use WP-API plugin:
i figured out how to get all posts for custom post type:
http://domain/wp-json/posts?type[]=customType
and i figured out how to get attachments:
http://domain/wp-json/media/
Now the problem is how to get images attached to single post. if I look at the soruce it seems to suggest a path like:
http://domain/wp-json/media/<postId>/
but I get an error:
[{"code":"json_post_invalid_type","message":"Invalid post type"}]
any Idea how to get this to work?
You can use the "parent" id argument, e.g:
$ curl http://demo.wp-api.org/wp-json/wp/v2/media?parent=<id>
where is the post's ID. What we do is ignore all versions of images except the original, which is found by looking for the GUID > rendered value, e.g:
guid: {
rendered: "http://demo.wp-api.org/wp-content/uploads/image-belonging-to-this-post.png"
}
As of this moment this functionality does not seem to be supported probably will be when the plugin goes into core but for now it is as is.
I ended up making my own json API to serve my needs by making the page templates recive emit JSON data.
Just an update to this old post. WP-API now supports getting media related to a particular post.
http://v2.wp-api.org/reference/media/
Code:
$ curl http://demo.wp-api.org/wp-json/wp/v2/media/<id>

Getting different feeds from one URL

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())

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.

Categories