How to integrate bitly api to shorten my link in iphone sdk

I created an application that gets the URL of my YouTube videos in a text box using the GData client library. Now I want to shorten this URL using bit api .. But I have no idea about this.

If someone did this in front of me, please tell me how you did it.

Thank,

Chakradhar.

+3
source share
4 answers

This is a quick and easy way to do this. You will need to register the .ly bit and get the username and API key.

NSString *username = @"user";
NSString *apiKey = @"R_11111111111111";
NSString *url = @"yoururl.com";

NSString *shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.bit.ly/v3/shorten?login=%@&apikey=%@&longUrl=%@&format=txt", username, apiKey, url]] encoding:NSUTF8StringEncoding error:nil];
+3
source

Here is the iOS wrapper for bit.ly api https://github.com/st3fan/iphone-bitly

+2
source

, , , Progress HUD:

  NSString *accessToken = YOUR_ACCESS_TOKEN;
  NSString *url = YOUR_URL;

  NSString *bitlyRequest = [NSString stringWithFormat:@"https://api-ssl.bitly.com/v3/shorten?access_token=%@&longUrl=%@",accessToken, url];
  NSString *bitlyResponse = [NSString stringWithContentsOfURL:[NSURL URLWithString:bitlyRequest] encoding:NSUTF8StringEncoding error:nil];

  NSData *data = [bitlyResponse dataUsingEncoding:NSUTF8StringEncoding];
  NSDictionary *bitlyDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

  NSString *bitlyUrl = bitlyDictionary[@"data"][@"url"];
+1

I suggest you start with the API documentation.

0
source

All Articles