1.Try This and also 3 way is bottom....
NSString *urlstr = videoUrl ;
NSString *urlstr = videoUrl ;
[urlstr retain];
NSString *apiEndpoint = [NSString stringWithFormat:@"http://ggl-shortener.appspot.com/?url=%@",urlstr];
[apiEndpoint retain];
NSLog(@"\n\n APIEndPoint : %@",apiEndpoint);
NSString *shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint]
encoding:NSASCIIStringEncoding
error:nil];
shortURL = [shortURL stringByReplacingOccurrencesOfString:@"{\"short_url\":\"" withString:@""];
shortURL = [shortURL stringByReplacingOccurrencesOfString:@"\",\"added_to_history\":false}" withString:@""];
[shortURL retain];
NSLog(@"Long: %@ - Short: %@",urlstr,shortURL);
2.....with tinyurl
2.....with tinyurl
NSString *urlstr =[[Result objectForKey:@"videourl"] stringByReplacingOccurrencesOfString:@" " withString:@""];///your videourl string
[urlstr retain];
NSString *apiEndpoint = [NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@",urlstr];
[apiEndpoint retain];
NSLog(@"\n\n APIEndPoint : %@",apiEndpoint);
NSString *shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint]
encoding:NSASCIIStringEncoding
error:nil];
[shortURL retain];
NSLog(@"Long: %@ - Short: %@",urlstr,shortURL);
and in last try bellow this one..
3....
and in last try bellow this one..
3....
- (NSURL *) shortURL {
NSString *uri = [self absoluteString];
NSString *fmt = [NSString stringWithFormat: @"http://api.bitly.com/v3/shorten?login=%@&apiKey=%@&longUrl=%@&format=txt", BITLY_LOGIN, BITLY_APIKEY, uri];
NSURL *requestUrl = [NSURL URLWithString: fmt];
NSString *shortUri = [NSString stringWithContentsOfURL: requestUrl];
return [NSURL URLWithString: shortUri];
}
No comments:
Post a Comment