Set video metadata after uploading to vimeo - ios

I've successfully uploaded video to vimeo by using API V3. Now, i want to set few metadata likes name, description, privacy.view etc to uploaded video.
When i tried with vimeo playground, it get success: https://developer.vimeo.com/api/endpoints/videos#/{video_id}
But in code, i tried following two way but didn't get success.
NSString *strURL = [NSString stringWithFormat:#"%#videos/%#?access_token=%#&name=%#&description=%#&privacy.view=%#", VIMEO_API_CALL_URL, strVideoID, VIMEO_ACCESS_TOKEN_TEMP, strName, strDescription, strPrivacyView];
NSURL *URL = [NSURL URLWithString:[strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];
[request setHTTPMethod:#"PATCH"];
and following also,
NSString *strURL = [NSString stringWithFormat:#"%#videos/%#?access_token=%#", VIMEO_API_CALL_URL, strVideoID, VIMEO_ACCESS_TOKEN_TEMP];
NSURL *URL = [NSURL URLWithString:[strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];
[request setHTTPMethod:#"PATCH"];
[request setValue:#"iOS_QuickTime" forHTTPHeaderField:#"name"];
[request setValue:#"This video is uploaded via iOS applcation and to perform last step by adding all required metadata." forHTTPHeaderField:#"description"];
[request setValue:#"nobody" forHTTPHeaderField:#"privacy.view"];
Here, VIMEO_API_CALL_URL is "https://api.vimeo.com/";
I'm wandering for solution. Till if any one can help me here.

Your access token should be included in a proper authentication header. Something like this:
Authorization: Bearer xxxxxxxxxtokenxxxxxxx
The values you are trying to set (title, description, privacy) should be query params, not header key / values. So your first approach is correct.
You could also consider using the Vimeo iOS SDK (I'm one of the authors) or just browse the codebase to help you get from point A to point B:
https://github.com/vimeo/VIMNetworking
Feel free to file issues on that repo too.

Related

How To Get Key Of goDaddy

Actually I want to created application of shortening URL , i have used GoDady by creating account at http://app.x.co/ But My URL doesnot get shorten.
This is my key
#define kGoDaddyAccountKey #"b201137c009311e6984efa163ee12fa9"
This is actually The method that do work for Shortening URL
- (IBAction)shortenURL:(id)sender
{
NSString *urlToShorten = self.webView.request.URL.absoluteString;
NSString *urlString = [NSString stringWithFormat:#"http://api.x.co/Squeeze.svc/text/%#?url=%#",kGoDaddyAccountKey,
[urlToShorten stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
shortURLData = [NSMutableData new];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
shortenURLConnection = [NSURLConnection connectionWithRequest:request
delegate:self];
}
But I get error like This.
Quite Interesting, Please Help.

Issue with NSURLSession and Content-Type

I am trying to upload a photo to a webservice, and I am using the following code:
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:imageToUpload], 0.5);
// 1
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
config.HTTPMaximumConnectionsPerHost = 1;
[config setHTTPAdditionalHeaders:#{#"Content-Type":#"multipart/form-data"}];
// 2
NSURLSession *upLoadSession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
// for now just create a random file name, dropbox will handle it if we overwrite a file and create a new name..
NSString *urlString =[NSString stringWithFormat:#"https://ABC.co.uk/photos?api_key=MYAPIKEY" ];
NSURL *webUrl = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:webUrl];
[request setHTTPMethod:#"POST"];
// 3
NSURLSessionUploadTask *uploadTask = [upLoadSession uploadTaskWithRequest:request fromData:imageData];
// 4
// uploadView.hidden = NO;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// 5
[uploadTask resume];
I receive an error 500, and I'm not sure what to do.
I have tried implementing AFNetworking, body data appending like This, This, and This. Yet, no luck.
The code above is from Ray Wenderlich's website: Here.
All I need to provide the server is this:
file (the image)
API Key (I tried using the NSMutableURLRequest's addValue:forHTTPHeaderField: but it didn't work, so I'm using it in the URL. I know it's not the best practice in terms of safety, but I'm getting so desperate as I've been working on this for over 10 hours! One step at the time!)
The Content-Type to be multipart/form-data
That's all I need to provide, and yet I'm not getting anywhere!
Can anyone please help?
Thank you in advance
UPDATE 1: So I made some alterations to the URL structure, and added the API key as a dictionary in HTTPBody, and now I am getting error 403.
It seems really weird that apple has not made any effort to serialise this part of connection. Anyway. I really appreciate anyone helping out!
Try setting the Content-Type in the request as well:
[request addValue:#"multipart/form-data" forHTTPHeaderField:#"Content-Type"];

iOS Trying to call web service and I'm getting a NSURLErrorDomain error

I'm trying to connect to a web service that if I hit it through Safari I get back some json, but when I hit it through code I get a NSURLErrorDomain error with the following description.
"The certificate for this server is invalid. You might be connecting to a server that is pretending to be "url" which could..."
Here is the code:
NSURL *url = [NSURL URLWithString:#"webservice_url"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"GET"];
NSError *error = nil;
NSHTTPURLResponse *responseCode = nil;
NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
Can anyone explain how to get around this? Also, it is a https web service.
The website doesn't have a HTTPS certificate. Try looking into this:
https://stackoverflow.com/a/15011030/4716039
In your code, the URLWithString value needs to be an actual URL. It is the same thing as going to Safari and typing in "webservice_url" as the entire URL instead of giving it the entire address. Instead you'll want to do something like the following:
NSURL *url = [NSURL URLWithString:#"https://www.urlgoeshere.com/getJSON"];
You can use like this -
NSURL *baseURL = [NSURL URLWithString:#"http://example.com/v1/"];
[NSURL URLWithString:#"foo" relativeToURL:baseURL];
// http://example.com/v1/foo

ios - making a remote call works on emulator but can not get it to work from live devices

I have a bit of a confusing situation. I have a form after which I create a url and make an asynchronous server call. That data does not need to be secure.
Here is what I have:
NSString *urlString = #"http://my.url.com/script_name.php?subject=hardcoded_string&body=";
NSString *inputString = textArea.text;
NSString *url_to_send = [NSString stringWithFormat:#"%#%#", urlString , inputString];
NSURL *url = [NSURL URLWithString:url_to_send];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url ];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
...
Is there something that I am doing incorrectly here in how I create the url?
Thanks!
it seems ok... take a look at asihttprequest libs, on google... that's a powerful wrapper for http connections... you should now set up the queue and add the request to the queue. finally you have to start the queue.

Problem related to NSURLConnection

today, I encountered a problem with NSURLConnection. I want to download the contents of the URL http://api.wunderground.com/api/fs3a45dsa345/geolookup/q/34.532900,-122.345.json. If I simply paste the URL into Safari, I get the correct response. However, if I do the same thing with NSURLConnection, I get a "not found" response. Here's the code I'm using:
NSURL *requestURL = [[NSURL alloc] initWithString:#"same url as above"];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:requestURL];
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest
delegate:self
startImmediately:YES];
What's the problem here?
Make sure you're escaping any special characters in the URL string by sending it a stringByAddingPercentEscapesUsingEncoding: message, for example:
NSString *s = [#"some url string" stringByAddingPercentEscapesUsingEncoding:NSUTFStringEncoding];
NSURL *requestURL = [NSURL URLWithString:s];
EDIT
It turns out the web service request is failing because the User-Agent header doesn't get set by default. To set it, use an instance of NSMutableURLRequest rather than NSURLRequest to create the request, as shown below:
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:myURL];
[myRequest setValue:#"My App" forHTTPHeaderField:#"User-Agent"];
Where is the delegate code? For async NSURLConnection there needs to be a delegate method to receive the returned data. Other options include sendSynchronousRequest: or if it must be async wrapping sendSynchronousRequest in a GCD block.

Resources