SuperLink and Sublink API Code Examples

There are many possible codes to use with the Yozio SuperLink and Sublink APIs. Here are some examples of code based upon the "link.update" method.

iOS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
NSString *url = @"http://api.yozio.com/v2.0/?app_key=YOUR_APP_KEY&
method=link.update&
short_url=g.c.dk&
name=Yozio+Email+Link+Test+updated&description=Link+from+email&
link_alias=yozio_email_invite&reassign_old_alias_to_this_link=true&
disable_original_short_url=true&
android_target_activity_class_name=com.yozio.yozio_android_sample_app.SecondActivity&
ios_target_view_controller_name=secondViewController&override_default_iphone_settings=true&
has_iphone_app=true&enable_iphone_deeplink=true&iphone_use_custom_download_url=true&
iphone_app_custom_download_url=http://www.apple.com&iphone_deeplink_url=yozio://main/&
override_default_ipad_settings=true&has_ipad_app=false&
ipad_no_app_url=http://www.google.com&override_default_android_settings=true&
android_google_play_url=https://play.google.com/store/apps/details?
id=com.yozio.yozio_android_sample_app&android_deeplink_url=yozio-sample-app-scheme://&
override_default_windows_settings=true&
windows_url=http://www.bing.com&override_default_fallback_settings=true&
fallback_url=http://www.yozio.com";


    NSMutableURLRequest *getRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url]];

    [getRequest setHTTPMethod:@"GET"];
    [getRequest setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];

    NSError *err;

    NSURLResponse *response;

    NSData *responseData = [NSURLConnection sendSynchronousRequest:getRequest   
    returningResponse:&response error:&err];

    NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: 
    NSJSONReadingMutableContainers error: &err];

    NSLog(@"%@", [jsonArray description]);
    NSLog(@"%@", [jsonArray description]);

Android

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public void getData() {
        HttpClient httpclient = new DefaultHttpClient();
        String url = 
"http://api.yozio.com/v2.0/?
method=link.update&
app_key=37c49567-f8fd-41f1-b22f-93fc21d9c77a&
name=Yozio+Test+Link&short_url=g.c.c8&meta_data[invite]=John&
meta_data[name]=Tom&link_alias=yozio_email_invite&
reassign_old_alias_to_this_link=true&disable_original_short_url=true&
ios_target_view_controller_name=SecondViewController&
android_target_activity_class_name=com.yozio.yozio_android_sample_app.SecondActivity&
web_url=http://welcome.yozio.com/&itunes_url=http://www.apple.com&
google_url=http://mail.google.com/&windows_url=http://www.bing.com";

        HttpGet httpget = new HttpGet(url);
        httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.2) 
        Gecko/20100316 Firefox/3.6.2");
        try {

            HttpResponse response = httpclient.execute(httpget);

            HttpEntity entity = response.getEntity();
            try{
                InputStream in = (InputStream) entity.getContent(); 
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                StringBuilder str = new StringBuilder();
                String line = null;
                while((line = reader.readLine()) != null){
                    str.append(line + "\n");
                }
                in.close();
                String responseStr = str.toString();
                Log.i("Yozio", "response - "+responseStr);
            }
            catch(IllegalStateException e){
                e.printStackTrace();
            }

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

PHP w/CURL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$url = 'http://api.yozio.com/v2.0/';

$params = array(
    'method' => 'link.update',
    'app_key' => 'YOUR_APP_KEY',
    'name' => 'Yozio Test Link',
    'short_url' => 'g.c.c8',
    'meta_data' => array(
        'invite' =>  'John',
        'name' => 'Tom',
    ),
    'link_alias' => 'yozio_email_invite',
    'reassign_old_alias_to_this_link' => true,
    'disable_original_short_url' => true,
    'ios_target_view_controller_name' => 'SecondViewController',
    'android_target_activity_class_name' => 'com.yozio.yozio_android_sample_app.SecondActivity',
    'web_url' => 'http://welcome.yozio.com/',
    'itunes_url' => 'http://www.apple.com',
    'google_url' => 'http://mail.google.com/',
    'windows_url' => 'http://www.bing.com',
);

$url .= '?' . http_build_query($params);

$defaults = array(
    CURLOPT_HEADER => FALSE,
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_FORBID_REUSE => TRUE,
    CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) 
    Gecko/20080311 Firefox/2.0.0.13', 
// user agent cannot be empty
);

$ch = curl_init();
curl_setopt_array($ch, $defaults);
$result = curl_exec($ch);

var_dump($result);

Use CURL in command line

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
curl  -A 'My User Agent'  -v -g 
"http://api.yozio.com/v2.0?
method=link.update&
app_key=YOUR_APP_KEY&
name=Yozio+Test+Link&short_url=g.c.c8&
meta_data\[invite\]=John&meta_data\[name\]=Tom&link_alias=yozio_email_invite&
reassign_old_alias_to_this_link=true&disable_original_short_url=true&
ios_target_view_controller_name=SecondViewController&
android_target_activity_class_name=com.yozio.yozio_android_sample_app.SecondActivity&
web_url=http://welcome.yozio.com/&itunes_url=http://www.apple.com&
google_url=http://mail.google.com/&windows_url=http://www.bing.com"