Need to process a request to youtube inside an iOS app - ios

If I take a browser and type http://www.youtube.com/get_video_info?video_id=$id&el=embedded&ps=default&eurl=&gl=US&hl=en into it, I get a bunch of text describing video with ID $id in a form of a file, that gets downloaded by a browser. The file contains a large string that is unique every time the request is performed.
Now, I need to gain access to that giant string inside iOS app.
Could you please tell me where to start digging? UIWebViews? Or maybe there's a simple solution?
Thanks in advance.

NSURL *url = [NSURL URLWithString:#"https://www.youtube.com/get_video_info?video_id=$id&el=embedded&ps=default&eurl=&gl=US&hl=en"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *idString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

Related

Display image on UIImageView using Web server image

I want to display an image on UIImageView calling the Web server image.
Because I want to replace and show it right away.
here's the code
NSURL *imageURL = [NSURL URLWithString:urlString];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
webImage.image = [UIImage imageWithData:imageData];
The problem is...
The image is displayed well at first,
but if I replaced the image on the web server with another image.(The file name is the same, only the file is replaced) It didn't change and still displayed the first image.
Please help me...
The code in the question seems flawed, i.e. you apparently do a network request in the UI thread. Such approach tends to make your application UI unresponsive. However, if we boil down the question to "Why NSData returns outdated data for the same URL?" then the answer is because it has internal caching. The caching logic could controlled either by the the response headers from the server (e.g. Expires) or with NSDataReadingUncached option (to suppress any caching logic):
NSData *data = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:nil];

Connect this NSSting with a String Variable

All I want is to change every time the NSString townLocation.
Because I take data from an API and I don't want to create different API for different location. Also I know that the "+" that I put on the link is not correct and there is not such think in Objective C but I want to make you understand what I want.
NSString*townLocation;
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://api.openweathermap.org/data/2.5/find?q="+townLocation+"&units=metric"]];
How I must do it ? Im sure you understand that I'm new at Objective C
Thank you
You only need to look into the most basic NSString documentation to find a method that will do that, stringWithFormat:.
NSString *urlString = [NSString stringWithFormat:#"http://api.openweathermap.org/data/2.5/find?q=%#&units=metric", townLocation];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
If you're new at Objective-C, a good place to find information like this is to simply search the internet or the iOS Developer Library for the class in question (in this case, NSString) to find a myriad of resources at your disposal. Another doc to check would be Formatting String Objects, which is linked in the stringWithFormat: section of the iOS Developer Library, to find more info about formatting strings.

NSData to NSString not working (for use in QCComposition)

I have A NSdata value that it needs to be converted into a string.
So far my app works fine loading a QC composition from a server however, I have a warning when I tell QC to load data from server.
It loads the file just fine but is there a way to avoid this worming?
I have tried to convert data to string using
NSString* newStr = [[NSString alloc] initWithData:urlData
encoding:NSUTF8StringEncoding];
HOwever, it is giving a null location of the file
Find the way I was loading the file with wrong method the correct one is:
QCComposition *qc = [QCComposition compositionWithData:urlData];

How to set Input Parameters when making Service Call

So I'm working on a small example on how to make a service call to a specific web service. I'm using the openweathermap.org web service. The link to this service is the following:
http://api.openweathermap.org/data/2.5/weather?q=London,uk
According to this link, I can search weather by city name. So I'm able to retrieve and NSLog the JSON data with the following code:
NSString *urlString = [NSString stringWithFormat:WXFORECAST, LOCATION];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(#"%#", json);
This does the bare minimum and retrieves the service. Now I would like to get my specific city instead of London.
If not, I would like to get JUST THE WEATHER part instead of getting the wind speed, and all that other garbage.
Here is the link for details on the API:
http://openweathermap.org/API#weather
Under that link there's a section that says this:
Restriction output:
To limit number of listed cities please setup cnt parameter api.openweathermap.org/data/2.5/find?lat=57&lon=-2.15&cnt=3
I believe this might be what I'm looking for but I don't know exactly how to use it...
All help is appreciated, thanks.
The API is accessed with a URL, try playing with this in your browser:
http://api.openweathermap.org/data/2.5/weather?q=New+York,us
See how I have a plus sign between "New" and "York"? That's to make sure the URL is valid, because they don't allow for spaces.
You have to figure out a way to get the URL you want in your variable. In your code, it's creating the URL using a format string stored in WXFORECAST. So, update that.
I don't have time to read through all of how that API works, but it's possible that you can't request that it gives you less information. But there's nothing stopping you from taking only what you need from it. It's all in that JSON dictionary, if you wanted to get the temperature your code might look like this.
NSArray *list = json[#"list"];
NSDictionary *london = list[0];
NSDictionary *main = london[#"main"];
NSString *temp = main[#"temp"];

Converting an iPhone IOS Video File Uploader to work with a file stored in document directory

This is my first real project. I have an app that captures several seconds of video using AVFoundation, outputs this to a file in the documents directory and lets the user preview the video before they upload it using HTTP and a PHP script on my website.
All the video capture and preview work perfectly but I am stuck on uploading the video file.
I learnt a lot from this simpleSDK video which shows how to achieve the desired effect using a video file stored in the apps main bundle.
The code from the tutorial that set up videoData ready to upload originally looked like this:
NSData *videoData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Movie" ofType:#"mov"]];
NSString *urlString = #"http://www.iphonedevnation.com/video-tutorial/upload.php";
The filename of the video file that I need to upload is always unique and generated using CFUUIDCreateString. I join this string to the path for the documents directory, add ".mov" to the end of it and save it into a text file for retrieving later.
This all works as I am able to retrieve the filename from the file and use it to preview the movie clip elsewhere in the app.
My path is in an NSString, that I have tried converting to NSURL and removing the file suffix to get it to work with the NSData *videoData.........line but it doesn't compile, I get an "No known class method for selector 'dataWithContentsOfFile:ofType.' error. I am targeting iOS 5 and using Xcode 4.3 with ARC and Storyboards.
I've been at this for best part of 5 hours now so hopefully someone can help. My code, which included tips from elsewhere on converting from a NSString to NSURL follows:
NSString *content = [[NSString alloc] initWithContentsOfFile:lastSavedTalentFilenamePath
usedEncoding:nil
error:nil];
NSLog(#"content=%#",content);
//Need to now remove the '.mov' file type identifier
NSString *shortContent= [content substringToIndex:[content length]-4];
NSLog(#"***************shortContent***************%#", shortContent);
NSURL *convertedContent = [NSURL fileURLWithPath:shortContent];
NSLog(#"***************convertedContent***********%#",convertedContent);
NSData *videoData = [NSData dataWithContentsOfFile:convertedContent ofType:#"mov"];];
There is no NSData method called dataWithContentsOfFile:ofType:
The methods available are:
+ dataWithContentsOfFile:
+ dataWithContentsOfFile:options:error:
both of which take the file location as an NSString so there's not need to convert to an NSURL

Resources