How can I get Giphy's gifs with using Swift Giphy Client? - ios

I found some framework which namely Giphy Client, to use the Giphy's gifs easily. But there is no tutorial on how to use it. Sorry for this rookie question. Can someone explain me to how can I search the gifs and get them with using this client?
Here is the gif search function :
func test(){
let gif1 = Giphy(apiKey: "dc6zaTOxFJmzC")
gif1.search("lol", limit: nil, offset: nil, rating: nil) { (gifs, pagination, err) in
}
}
I really don't know what's in the gifs value and I'm struggling because of that. There is a lot of subclass like url, id or rankings, but I can't figured it out.

All the information is available on the GitHub page you linked in your question. To find more about the gifs variable, you can use Xcode's Utilities menu (the right side bar) to see documentation when you click on a variable or function.
Alternatively, you can jump to the definition of a variable by holding command and clicking it. The information about the Gif object is available here on GitHub as well.
It looks like the gifs variable is an optional array of Gif objects (its type is [Gif]?).
The Gif object has some useful properties like id, rating, and giphyURL (a URL pointing to the actual gif image).
Since you most likely want to get the images themselves, you can make network requests to get the actual image data. This has already been covered extensively on Stack Overflow. Here is an answer to get you started with getting image data from a url: https://stackoverflow.com/a/27712427/6658553

Related

authorProfileImageUrl returns only a tiny thumbnail

I'm trying to use YouTube Data API to get a list of comments for a video.
The problem is that the field authorProfileImageUrl in the response contains a URL to a tiny thumbnail (28x28 pixels) of the profile image instead of the bigger one (48x48) that can be seen in YouTube's comment section. How can I retrieve the bigger one? Am I missing some magic parameter in the request that selects the size of the profile images in comments?
Here's my request URL:
https://www.googleapis.com/youtube/v3/commentThreads?videoId=VIDEO_ID&part=snippet&fields=pageInfo,items(snippet(topLevelComment(id,snippet(authorDisplayName,authorChannelUrl,authorProfileImageUrl,authorChannelId,textDisplay,likeCount,publishedAt)),totalReplyCount))&maxResults=3&key=API_KEY
Edit:
Here's an example profile pic URL i get:
https://yt3.ggpht.com/-b-fXZSZ0hPw/AAAAAAAAAAI/AAAAAAAAAAA/mq4JpF46xq4/s28-c-k-no-mo-rj-c0xffffff/photo.jpg
^^
I noticed that the marked part seems to select the size, because when I change the 28 to 48, the size of the profile pic changes too.
I could change it "manually" with some fancy regexp, and it will work, but it will also rely on implementation details that are undocumented and that may change in future and render the application broken :P So it really would be better if there was a documented API way to do that.
Seems like nobody knows how to solve this, ho here's my temporary solution.
It works, but it depends on an implementation detail that can change in the future and then the solution will break apart and will have to be corrected :q
I accept my own answer for now, but when someone posts a better one, I'll accept it instead.
The solution:
I made a simple function that searches for the image size in the URL string and replaces it with a bigger size.
function small2big(url)
{
return url.replace(/(\/.*s)28(.*\/photo.jpg)$/,"$1"+"48"+"$2");
}
Oh, and here's my middle finger for you, Google: ,,|,,
It seems that actually removing everything right at the 's28' will display the entire image without specifying a size.
For example, instead of this:
https://yt3.ggpht.com/-b-fXZSZ0hPw/AAAAAAAAAAI/AAAAAAAAAAA/mq4JpF46xq4/s28-c-k-no-mo-rj-c0xffffff/photo.jpg
You can use this: https://yt3.ggpht.com/-b-fXZSZ0hPw/AAAAAAAAAAI/AAAAAAAAAAA/mq4JpF46xq4/
And it will return the full size image.
In my case, using php I simply:
function bigAvatar($url) {
$url = substr($url, 0, strpos($url, 's28'));
return $url;
}
Again, if google decides to change this in the future, this would break. But for now, it works.

Search iTunes for podcast by title

I'd like to find the specific podcast episode titled "#1: The Single White Guy Focus Group." According to the iTunes search API, I believe I should be able to find it with the following:
https://itunes.apple.com/search?term=%231:+The+Single+Straight+Guy+Focus+Group&entity=podcast&attribute=keywordsTerm
But that returns an empty JSON. I also tried
https://itunes.apple.com/search?term=The+Single+Straight+Guy+Focus+Group&entity=podcast
... and ...
https://itunes.apple.com/search?term=The+Single+Straight+Guy+Focus+Group
... but I always get the same result.
{
"resultCount":0,
"results": []
}
I'm baffled. I know the episode is in there - here it is.
https://itunes.apple.com/us/podcast/1-single-straight-guy-focus/id775053292?i=1000375469754&mt=2
(posting full url so deliberately, so you can see that indeed there is a url which does point to that specific episode)
So why can't I find it?
EDIT: Note that I am doing this in an Obj-C iOS app, in case that is relevant.
After a TON of hair-pulling, I've found that there is an undocumented entity (podcastEpisode) that does what we all want.
So, on the off-chance the original poster is still at this after 3 years (or more likely other frustrated folks like myself browsing) - try this (using the original example):
https://itunes.apple.com/search?term=The+Single+Straight+Guy+Focus+Group&entity=podcastEpisode
Unfortunately apple API searches only by the title of the podcast and not by the title of the episode. I'm trying to add a search by episode on my app but to no avail so far

Reload data in Amchart

I'm using this library,
https://github.com/ChimpStudios/AmCharts
It works cool, but i didn't find how to reload existing chart. When i call multiple times:
self.mapView.chart = self.map
self.mapView.drawChart()
map disappear or it's color set to black. In original AmChart for JavaScript, object has method validateData, but this method i didn't find in IOS library.
If someone used this library, please help, because in github author not answer.
I'm unfamiliar with this specific library/wrapper, but looking in the repo, it does appear that both chart.validateData() and chart.validateNow() are supported.
Example usage in ChartView.m

photoswipe: pid/gid link to particular photo

I wonder how photoswipe builds URL to a particular image in a gallery?
I see that for each image in a gallery the following URL is built: [BASE_URL]#&gid=2&pid=3. If I get it right, the pid/gid values are taken in the order of gallery/photo appearance on a page. Which presents problem for dynamic content when galleries/photos are shuffled (sorted, deleted, etc.)
Is there a way to overrule that logic such that static ID's (e.g. database PK's) are used?
Thank you.
After digging into the sources I found out that if gallery element has attribute data-pswp-uid= set to some value, then that value is used in URL as gid.
Unfortunately, same trick on an image/figure didn't do.

How to get bigger size pictures if me/home items in facebook sdk

Now i'm using Facebook SDK on my ASP.NET MVC5 project, and for data query I use Graph Api.
When I read a data from "me/home", almost each read item of it have key called "picture", that represents image attached to post. But it is thumnbail size, how can I get it bigger resolution and better quality?
Link i got look smth like this:
https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-xpa1/v/t1.0-9/s130x130/1902827_682459971849744_3936731463452030828_n.jpg?oh=a31397c18fc806dcd1b60565009fd50b&oe=54BAA327&gda=1420888048_5c40d0ab0d0b0f5636d7965138f7f6ab
I hope for your help.
Thank you for your time
There is a variable in the API "type" using that you can specify the sizes of the image
The type parameter can be one of square, small, normal, or large for profile pictures or thumbnail, normal, album for album pictures.
image src would be something like this
https://graph.facebook.com/xxx/picture?access_token=yyy&type=normal
you can find more information # http://developers.facebook.com/docs/reference/api/user/
string imageUrl = fb.Get("/me?fields=picture.type(large)").ToString();

Resources