Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Working with Microsoft OneDrive albums, photos, videos, audio, and tags

Your apps can use the Live Connect APIs to create, read, update, and delete a Microsoft OneDrive user's albums (a special type of folder that can store photos, videos, audio, as well as child albums and child folders), photos, videos, and audio. Your apps can also read, create, and delete tags (a type of comment) that users can add to photos, videos, and audio.

To make full use of the code examples in this topic, you can use them in the context of larger code reference samples that we provide in Working with the code examples. To request the required scopes, see the code patterns in Obtaining user consent.

Reading albums

To get info about an album, use code like this. The wl.photos or wl.skydrive scope is required.

[JavaScript and HTML for Windows Store apps]


function readAlbumProperties_onClick() {
    WL.login({
        scope: "wl.photos"  
    }).then(
        function (response) {
            WL.api({
                path: "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!165",
                method: "GET"
            }).then(
                function (response) {
                    document.getElementById("infoArea").innerText = 
                        "Album properties: name = " + response.name + ", ID = " + response.id;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                } 
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


[C# for Windows Store apps and Windows Phone apps]


private async void btnReadAlbum_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.GetAsync("folder.8c8ce076ca27823f.8C8CE076CA27823F!134");
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = string.Join(" ", "Album name:", result.name, "ID:", result.id);
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error getting album info: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) getAlbumProperties
{
    [self.liveClient getWithPath:@"folder.95d463b9efcca0e1.95D463B9EFCCA0E1!108" 
                        delegate:self];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSString *albumId = [operation.result objectForKey:@"id"];
    NSString *albumName = [operation.result objectForKey:@"name"];
    NSString *albumDescription = [operation.result objectForKey:@"description"];
    NSString *albumLink = [operation.result objectForKey:@"link"];
    NSString *albumType = [operation.result objectForKey:@"type"];
    self.displayLabel.text = [NSString stringWithFormat:
                              @"Album Properties:\n"
                              @"\tId. %@\n"
                              @"\tName. %@\n"
                              @"\tDescription. %@\n"
                              @"\tLink. %@\n"
                              @"\tType. %@\n"
                              , albumId, 
                              albumName, 
                              albumDescription, 
                              albumLink,
                              albumType];
}


[Java for Android]


public void readAlbum() {
    String albumid = "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!111";
       client.getAsync(albumid , new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error reading album: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Album info: " +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       });
}


[REST]

GET https://apis.live.net/v5.0/folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!111?access_token=ACCESS_TOKEN

In the preceding code, change the album ID to this:

  • A different album ID, to get info about another album.
  • me/albums, to get info about all of the signed-in user's albums.
  • /me/skydrive/shared/albums, to get info about all of the signed-in user's shared albums.
  • USER_ID/albums, to get info about all of a user's albums that correspond to a valid USER_ID.

You can also do this:

  • Use ALBUM_ID/photos or ALBUM_ID/videos, to get a list of all photos or videos in an album. Then your code can make another call that uses a specific photo ID or video ID to get the info for that photo or video.
  • Use ALBUM_ID/files to get a list of all photos, videos, audio, child albums, and child folders in an album. Then your code can make another call that uses a specific photo ID, video ID, album ID, audio ID, or folder ID to get the info for that photo, video, album, audio, or folder.

    Note  You can get info about an album's photos, videos, audio, child albums, and child folders only.

  • Use ALBUM_ID/picture to get a picture of an album's cover.
  • Get a limited number of items by using the limit parameter in the preceding code to specify the number of items to get. For example, to get the first two items, use ALBUM_ID/files?limit=2.
  • Set the first item to start getting by using the offset parameter in the preceding code to specify the index of the first item to get. For example, to get two items starting at the third item, use ALBUM_ID/files?limit=2&offset=3.

    Note  In the JavaScript Object Notation (JSON)-formatted object that's returned, you can look in the paging object for the previous and next structures to get the offset and limit parameter values of the previous and next entries.

  • Set the items' sort criteria by using the sort_by parameter in the preceding code to specify the criteria: updated, name, size, or default. For example, to sort the items by name, use ALBUM_ID/files?sort_by=name.
  • Set the items' sort order by using the sort_order parameter in the preceding code to specify the order: ascending or descending. For example, to sort the items in descending order, use ALBUM_ID/files?sort_by=descending.

Top

Deleting albums

To remove an album, use code like this. The wl.skydrive_update scope is required.

[JavaScript and HTML for Windows Store apps]


function deleteAlbum_onClick() {
    WL.login({ 
        scope: "wl.skydrive_update"
    }).then(
        function (response) {
            WL.api({
                path: "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!165",
                method: "DELETE" 
            }).then(
                function (response) {
                    document.getElementById("infoArea").innerText = "Deleted album.";
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                } 
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
 }


[C# for Windows Store apps and Windows Phone apps]


private async void btnDeleteAlbum_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.DeleteAsync("folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!148");
        this.infoTextBlock.Text = "Album deleted.";
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error deleting album: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) deleteAlbum
{
    [self.liveClient deleteWithPath:@"folder.95d463b9efcca0e1.95D463B9EFCCA0E1!108"
                           delegate:self];    
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"API call successful!" 
                                                    message:@"Album deleted successfully"
                                                   delegate:self 
                                          cancelButtonTitle:@"Ok" 
                                          otherButtonTitles:nil, 
                          nil];
    [alert show];
    [alert release];
}


[Java for Android]


public void deleteAlbum() {
    String albumid = "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!137";
    client.deleteAsync(albumid, new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error deleting album: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            resultTextView.setText("Album deleted.");
           }
       });
}


[REST]

DELETE https://apis.live.netv/5.0/folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!111?access_token=ACCESS_TOKEN

In the preceding code, change the album ID to the album ID of the album that you want to remove.

Top

Creating albums

To add a new album, use code like this. The wl.skydrive_update scope is required.

[JavaScript and HTML for Windows Store apps]


function createAlbum_onClick() {
    WL.login({ 
        scope: "wl.skydrive_update"
    }).then(
        function (response) {
            WL.api({
                path: "/me/albums",
                method: "POST",
                body: {
                    "name": "My new album",
                    "description": "A new photo album"
                } 
            }).then(
                function (response) {
                    document.getElementById("infoArea").innerText = 
                        "Created album. Name: " + response.name + ", ID: " + response.id;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                } 
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


You can also add a new album by using POST to me/skydrive, and passing the type attribute with a value of "album", as shown here.



...
WL.api({ 
    path: "/me/skydrive", 
    method: "POST", 
    body: {
        "name": "My new album", 
        "description": "A new photo album"
    } 
    type: "album" }, 
onCreateAlbumComplete);
...

[C# for Windows Store apps and Windows Phone apps]


private async void btnCreateAlbum_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var albumData = new Dictionary<string, object>();
        albumData.Add("name", "A brand new album");
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.PostAsync("me/albums", albumData);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = string.Join(" ", "Created album:", result.name, "ID:", result.id);
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error creating album: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) createAlbum
{
    NSDictionary * newAlbum = [[NSDictionary dictionaryWithObjectsAndKeys:
                                @"Vacation Pics",@"name",
                                @"Family vacation",@"description",
                                @"album",@"type",
                                nil] retain];

    [self.liveClient postWithPath:@"me/skydrive" 
                         dictBody:newAlbum
                         delegate:self];
    [newAlbum release];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSString *albumId = [operation.result objectForKey:@"id"];
    NSString *albumName = [operation.result objectForKey:@"name"];
    NSString *albumDescription = [operation.result objectForKey:@"description"];
    NSString *albumLink = [operation.result objectForKey:@"link"];
    NSString *albumType = [operation.result objectForKey:@"type"];
    self.displayLabel.text = [NSString stringWithFormat:
                              @"Album Properties:\n"
                              @"\tId. %@\n"
                              @"\tName. %@\n"
                              @"\tDescription. %@\n"
                              @"\tLink. %@\n"
                              @"\tType. %@\n"
                              , albumId, 
                              albumName, 
                              albumDescription, 
                              albumLink,
                              albumType];
}


[Java for Android]


public void createAlbum() {
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error creating album: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Album created:" +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.skydrive_update" }), new LiveAuthListener() {
        public void onAuthError(LiveAuthException exception, Object userState) {
            resultTextView.setText("Error signing in: " + exception.getMessage());
        }
        public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
            try {
                JSONObject body = new JSONObject();
                body.put("name", "MyNewAlbum");
                body.put("description", "My new album");
            client.postAsync("me/albums", body, opListener);    
            }
            catch(JSONException ex) {
                resultTextView.setText("Error signing in: " + ex.getMessage());
            }
        }
    });        
}


[REST]

POST https://apis.live.net/v5.0/me/albums

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name": "My example album"
}

Note  You can create albums only in the user's top-level OneDrive folder, represented here as me/albums.

For details about the minimum required and optional structures that your app must provide when using POST, see the "Album object" section in REST reference.

Top

Updating albums

To change info for an existing album, use code like this. The wl.skydrive_update scope is required.

[JavaScript and HTML for Windows Store apps]


function updateAlbumProperties_onClick() {
    WL.login({ 
        scope: "wl.skydrive_update"
    }).then(
        function (response) {
            WL.api({
                path: "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!165",
                method: "PUT",
                body: {
                    name: "My new sample album name"
                } 
            }).then(
                function (response) {
                    document.getElementById("infoArea").innerText = 
                        "Updated album. Name: " + response.name + ", ID: " + response.id;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                } 
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


[C# for Windows Store apps and Windows Phone apps]


private async void btnUpdateAlbum_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var albumData = new Dictionary<string, object>();
        albumData.Add("name", "Nature Photography 2");
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.PostAsync("folder.8c8ce076ca27823f.8C8CE076CA27823F!134", albumData);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = "Album updated:" + result.name;
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error updating album: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) updateAlbum
{
    NSDictionary * updatedAlbum = [[NSDictionary dictionaryWithObjectsAndKeys:
                                    @"2011 photo album",@"description",
                                    nil] retain];
    [self.liveClient putWithPath:@"folder.95d463b9efcca0e1.95D463B9EFCCA0E1!108" 
                        dictBody:updatedAlbum
                        delegate:self];
    [updatedAlbum release];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"API call successful!" 
                                                    message:@"Album updated successfully"
                                                   delegate:self 
                                          cancelButtonTitle:@"Ok" 
                                          otherButtonTitles:nil, 
                          nil];
    [alert show];
    [alert release];
}


[Java for Android]


public void updateAlbum() {
    final String albumId = "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!111";
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error updating album: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Album updated:" +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.skydrive_update" }), 
        new LiveAuthListener() {
               public void onAuthError(LiveAuthException exception, Object userState) {
                   resultTextView.setText("Error signing in: " + exception.getMessage());
               }
            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                try {
                    JSONObject body = new JSONObject();
                    body.put("name", "MyChangedAlbum");
                    body.put("description", "My changed album");
                       client.putAsync(albumId, body, opListener);    
                }
                catch(JSONException ex) {
                    resultTextView.setText("Error updating album: " + ex.getMessage());
                }
               }
        }
    );        
}


[REST]

PUT https://apis.live.net/v5.0/folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!111

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name": "My example album has changed"
}

For details about the minimum required and optional structures that your app must provide when using PUT, see the "Album object" section in REST reference.

Top

Reading photo, video, and audio properties and their contents

To get info about a photo, video, or audio, use code like this. The wl.skydrive scope is required.

[JavaScript and HTML for Windows Store apps]


function readPhotoProperties_onClick() {
    WL.login({
        scope: "wl.skydrive"
    }).then(
        function (response) {
            WL.api({
                path: "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131",
                method: "GET"
            }).then(
                function (response) {
                    document.getElementById("infoArea").innerText = 
                        "Photo properties: name = " + response.name + ", ID = " + response.id;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                } 
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
 }


[C# for Windows Store apps and Windows Phone apps]


private async void btnReadPhoto_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        StorageFile pngFile = await ApplicationData.Current.LocalFolder.GetFileAsync("photo.png");
        await liveClient.BackgroundDownloadAsync("file.8c8ce076ca27823f.8C8CE076CA27823F!129/picture?type=thumbnail", pngFile);
        var imgSource = new BitmapImage();
        imgSource.SetSource(await pngFile.OpenReadAsync());
        imgResult.Source = imgSource;
        this.infoTextBlock.Text = "Photo downloaded.";
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error downloading photo: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) getFileProperties
{
    [self.liveClient getWithPath:@"file.95d463b9efcca0e1.95D463B9EFCCA0E1!113" 
                        delegate:self];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSString *fileId = [operation.result objectForKey:@"id"];
    NSString *fileName = [operation.result objectForKey:@"name"];
    NSString *fileDescription = [operation.result objectForKey:@"description"];
    NSString *fileSize = [operation.result objectForKey:@"size"];
    self.displayLabel.text = [NSString stringWithFormat:
                              @"File Properties:\n"
                              @"\tId. %@\n"
                              @"\tName. %@\n"
                              @"\tDescription. %@\n"
                              @"\tSize. %@\n"
                              , fileId, 
                              fileName, 
                              fileDescription, 
                              fileSize];
}


[Java for Android]


public void readPhoto() {
    String photoId = "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131";
       client.getAsync(photoId , new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error reading photo: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Photo info: " +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       });
}


Note  Secure Hypertext Transfer Protocol (HTTPS) is not supported for audio and video playback in Android versions earlier than 3.1. OneDrive uses HTTPS by default, so to return an HTTP URL that will work with Android versions earlier than 3.1, add the return_https_resource=false query parameter to the file ID for audio or video files.

For example, to use the preceding code example with a video or audio file on an Android version earlier than 3.1, you would add the query string to the file ID like this.

file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131?return_https_resource=false

For more info about media formats support in Android, see Android Supported Media Formats.

[REST]

GET https://apis.live.netv/5.0/photo.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!112?access_token=ACCESS_TOKEN

In the preceding code, change the photo ID to a different photo ID, video ID, or audio ID to get info about another photo, video, or audio.

You can also do this.

  • Get a picture of a photo or video by using /picture with the optional type parameter in the preceding code and one of these values: small, normal (default if the type parameter is not specified), album, thumbnail, or full. For example, to get a photo's thumbnail picture, use PHOTO_ID/picture?type=thumbnail.
  • Get a video's contents by using VIDEO_ID/video.

Top

Updating photo, video, and audio properties

To change info about a photo, video, or audio, use code like this. The wl.skydrive_update scope is required.

[JavaScript and HTML for Windows Store apps]


function updatePhotoProperties_onClick() {
    WL.login({ 
        scope: "wl.skydrive_update"
    }).then(
        function (response) {
            WL.api({
                path: "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131",
                method: "PUT",
                body: {
                    name: "Hydrangeas2.jpg"
                } 
            }).then(
                function (response) {
                    document.getElementById("infoArea").innerText = 
                        "Updated photo properties. Name: " + response.name + ", ID: " + response.id;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                } 
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


[C# for Windows Store apps and Windows Phone apps]


private async void btnUpdatePhoto_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var photoData = new Dictionary<string, object>();
        photoData.Add("name", "Tulips21.jpg");
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.PutAsync("file.8c8ce076ca27823f.8C8CE076CA27823F!129", photoData);
        this.infoTextBlock.Text = "Photo renamed.";
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error renaming photo: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) updateFileProperty
{
    NSDictionary * updatedFile = [[NSDictionary dictionaryWithObjectsAndKeys:
                                   @"Having fun at the beach",@"description",
                                   nil] retain];
    [self.liveClient putWithPath:@"file.95d463b9efcca0e1.95D463B9EFCCA0E1!113" 
                        dictBody:updatedFile
                        delegate:self];
    [updatedFile release];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"API call successful!" 
                                                    message:@"File updated successfully"
                                                   delegate:self 
                                          cancelButtonTitle:@"Ok" 
                                          otherButtonTitles:nil, 
                          nil];
    [alert show];
    [alert release];
}


[Java for Android]


public void updatePhoto() {
    final String fileId = "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131";
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error updating photo: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Photo updated:" +
                "\nID = " + result.optString("id") +
                "\nName = " + result.optString("name");
               resultTextView.setText(text);
           }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.skydrive_update" }), 
        new LiveAuthListener() {
               public void onAuthError(LiveAuthException exception, Object userState) {
                   resultTextView.setText("Error signing in: " + exception.getMessage());
               }
            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                try {
                    JSONObject body = new JSONObject();
                    body.put("name", "Hydrangeas3.jpg");
                    body.put("description", "Pretty flowers");
                       client.putAsync(fileId, body, opListener);    
                }
                catch(JSONException ex) {
                    resultTextView.setText("Error updating photo: " + ex.getMessage());
                }
               }
        }
    ); 
}


[REST]

PUT https://apis.live.net/v5.0/photo.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!112

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name": "My example photo has changed"
}

In the preceding code, change the photo ID to the photo ID, video ID, or audio ID of the photo, video, or audio for which you want to update the properties.

For details about the minimum required and optional structures that your app must provide when using PUT, see the "Photo object", "Video object", or "Audio object" section in REST reference.

Top

Uploading, updating, and deleting photos, videos, and audios

The Live Connect APIs consider a photo, video, or audio to be the same as a file when uploading, updating, and deleting the contents of a photo, video, or audio.

To add the contents of a photo, video, or audio, see the "Uploading files" section in Folders and files.

To update the contents of a photo, video, or audio, see the "Updating uploaded files" section in Folders and files.

To delete the contents of a photo, video, or audio contents, see the "Deleting uploaded files" section in Folders and files.

Top

Reading tags

To get info about tags, use code like this. The wl.skydrive scope is required.

[JavaScript and HTML for Windows Store apps]


function enumeratePhotoTags_onClick() {
    WL.login({
        scope: "wl.skydrive"
    }).then(
        function (response) {
            WL.api({
                path: "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131/tags",
                method: "GET"
            }).then(
                function (response) {
                    msg = "People tagged in the photo: ";
                    items = response.data;
                    for (index in items) {
                        if (index != 0)
                            msg += ", "
                        msg += items[index].user.name; 
                    }
                    document.getElementById("infoArea").innerText = msg;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                } 
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


[C# for Windows Store apps and Windows Phone apps]


private async void btnReadTag_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.GetAsync("file.8c8ce076ca27823f.8C8CE076CA27823F!129/tags");
        StringBuilder tags = new StringBuilder("People tagged:\n");
        dynamic result = operationResult.Result;
        dynamic data = result.data;
        if (data.Count > 0)
        {
            foreach (dynamic userData in data)
            {
                dynamic user = userData.user;
                if (user != null)
                {
                    if (user.name != null)
                    {
                        if (tags.Length != 0)
                        {
                            tags.Append("\n");
                        }
                        tags.Append("\t");
                        tags.Append(user.name);
                        tags.Append("\n");
                        tags += "\t" + user["name"].ToString() + "\n";
                    }
                }
            }
            this.infoTextBlock.Text = tags.ToString();
        }
        else
        {
            this.infoTextBlock.Text = "No tags.";
        }
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error getting tag(s) info: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) getPhotoTags
{
    [self.liveClient getWithPath:@"file.95d463b9efcca0e1.95D463B9EFCCA0E1!116/tags"
                        delegate:self];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSArray *tags = [operation.result objectForKey:@"data"];
    for (NSDictionary *tag in tags)
    {
        NSDictionary *userInfo = [tag objectForKey:@"user"];
        NSString *positionX = [tag objectForKey:@"x"];
        NSString *positionY = [tag objectForKey:@"y"];
        NSString *tagId = [tag objectForKey:@"id"];
        NSString *userId = [userInfo objectForKey:@"id"];
        NSString *userName = [userInfo objectForKey:@"name"];
        self.displayLabel.text = [NSString stringWithFormat:
                                  @"Tag Properties:\n"
                                  @"\tId. %@\n"
                                  @"\tUser Id. %@\n"
                                  @"\tUser Name. %@\n"
                                  @"\tPosition X. %@\n"
                                  @"\tPosition Y. %@\n"
                                  , tagId,
                                  userId, 
                                  userName, 
                                  positionX,
                                  positionY];
    }   
}


[Java for Android]


public void readTags() {
    String photoId = "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131/tags";
       client.getAsync(photoId , new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error reading tags: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String msg = "Tag info:\n";
            JSONArray  items = result.optJSONArray("data");
            for (int i = 0; i < items.length(); i++) {
                JSONObject tag = items.optJSONObject(i);
                JSONObject user = tag.optJSONObject("user");
                msg += user.optString("name") + "\n";
            }
               resultTextView.setText(msg);
           }
       });
}


[REST]

GET https://apis.live.netv/5.0/file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131/tags?access_token=ACCESS_TOKEN

In the preceding code, change the photo ID to a different photo ID, video ID, or audio ID, to get info about the tags for another photo, video, or audio. You can also specify a tag's ID to get info about that individual tag.

You can also do this:

  • Get a limited number of tags by using the limit parameter in the preceding code to specify the number of items to get. For example, to get the first two tags, use PHOTO_ID/tags?limit=2.
  • Set the first tag to start getting by using the offset parameter in the preceding code to specify the index of the first item to get. For example, to get two items starting at the third item, use PHOTO_ID/tags?limit=2&offset=3.

    Note  In the JSON-formatted object that's returned, you can look in the paging object for the previous and next structures to get the offset and limit parameter values of the previous and next entries.

Top

Deleting tags

To delete a tag, use code like the this. The wl.skydrive_update scope is required.

Note  Only the owner of an item can delete that item's tags.

[JavaScript and HTML for Windows Store apps]


function deleteTag_onClick() {
    WL.login({
        scope: "wl.skydrive_update"
    }).then(
        function (response) {
            WL.api({
                path: "tag.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131.OnqQnWO_Ye9L3fTKW154K7jHQvM",
                method: "DELETE"
            }).then(
                function (response) {
                    document.getElementById("infoArea").innerText = "Tag deleted.";
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


[C# for Windows Store apps and Windows Phone apps]


private async void btnDeleteTag_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.DeleteAsync("tag.22688711f5410e6c.22688711f5410e6c!767.PRaXZrdHI1uYGQYi9CU0StrzHak");
        this.infoTextBlock.Text = "Tag deleted.";
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error deleting tag: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) deleteTags
{
    [self.liveClient deleteWithPath:@"tag.95d463b9efcca0e1.95d463b9efcca0e1!116.0c6Cdgik364WTnvMuzvSGOqadrc"
                           delegate:self];    
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"API call successful!" 
                                                    message:@"Tag deleted successfully"
                                                   delegate:self 
                                          cancelButtonTitle:@"Ok" 
                                          otherButtonTitles:nil, 
                          nil];
    [alert show];
    [alert release];
}


[Java for Android]


public void deleteTag() {
    String tagId = "tag.2e82e8a5445fe036.2e82e8a5445fe036!1111.47CinUEOE1qvXn3UqNHvV2EkAKg";
    client.deleteAsync(tagId , new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error deleting tag: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            resultTextView.setText("Tag deleted.");
           }
       });
}


[REST]

DELETE https://apis.live.net/v5.0/tag.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131.PlP_Zr6OeZfqtMa%3DJVLP11mNcD0?access_token=ACCESS_TOKEN

In the preceding code, change the tag ID to the tag ID of the tag that you want to remove.

Top

Creating tags

To create a tag, use code like the following. The wl.skydrive_update scope is required.

Tip  You can create tags for items that are owned by, or shared with, the signed-in user.

  • To create a tag for an item that is owned by the signed-in user, replace the photo ID with the item's ID in the code that follows.
  • To create a tag for an item that is shared with the signed-in user, first use the wl.contacts_skydrive scope to make a GET request to /USER_ID/skydrive/shared, where USER_ID is either me or the user ID of the consenting user. Then, if the item is included in the response, replace the photo ID with the item's ID in the code that follows.

[JavaScript and HTML for Windows Store apps]


function createTag_onClick() {
    WL.login({
        scope: "wl.skydrive_update"
    }).then(
        function (response) {
            WL.api({
                path: "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131/tags",
                method: "POST",
                body: {
                    "user": {
                        "name": "Stig Struve-Christensen",
                        "id": "a6b2a7e8f2515e5e"
                    },
                    "x": 0.5,
                    "y": 0.5
                }
            }).then(
                function (response) {
                    document.getElementById("infoArea").innerText = "Tag created.";
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}


[C# for Windows Store apps and Windows Phone apps]


private async void btnCreateTag_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var userData = new Dictionary<string, object>();
        userData.Add("name", "Roberto Tamburello");
        userData.Add("id", "8c8ce076ca27823f");
        var tagData = new Dictionary<string, object>();
        tagData.Add("user", userData);
        tagData.Add("x", 43.8986);
        tagData.Add("y", 54.4138);
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.PostAsync("file.8c8ce076ca27823f.8C8CE076CA27823F!129/tags", tagData);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = string.Join(" ", "Tag created, ID:", result.id);
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error creating tag: " + exception.Message;
    }
}


[Objective-C for iOS]


-(void) createTag
{
    NSDictionary * user = [[NSDictionary dictionaryWithObjectsAndKeys:
                            @"John Smith", @"name",
                            nil] retain];
    NSDictionary * newTag = [[NSDictionary dictionaryWithObjectsAndKeys:
                              @"50",@"x",
                              @"70",@"y",
                              user,@"user",
                              nil] retain];
    [self.liveConnectClient postWithPath:@"file.1cfa02017372544c.1CFA02017372544C!209/tags"
                                dictBody:newTag                                    
                                delegate:self];
}

- (void) liveOperationSucceeded:(LiveOperation *)operation
{
    NSDictionary *userInfo = [operation.result objectForKey:@"user"];
    NSString *positionX = [operation.result objectForKey:@"x"];
    NSString *positionY = [operation.result objectForKey:@"y"];
    NSString *tagId = [operation.result objectForKey:@"id"];
    NSString *userId = [userInfo objectForKey:@"id"];
    NSString *userName = [userInfo objectForKey:@"name"];
    self.displayLabel.text = [NSString stringWithFormat:
                              @"Tag Properties:\n"
                              @"\tId. %@\n"
                              @"\tUser Id. %@\n"
                              @"\tUser Name. %@\n"
                              @"\tPosition X. %@\n"
                              @"\tPosition Y. %@\n"
                              , tagId,
                              userId, 
                              userName, 
                              positionX,
                              positionY];
}


[Java for Android]


public void createTag() {
    final String tagsPath = "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131/tags";
    final LiveOperationListener opListener = new LiveOperationListener() {
        public void onError(LiveOperationException exception, LiveOperation operation) {
               resultTextView.setText("Error creating tag: " + exception.getMessage());
           }
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            String text = "Photo tagged:\nID = " + result.optString("id");
               resultTextView.setText(text);
           }
       };
    auth.login(this, Arrays.asList(new String[] { "wl.skydrive_update" }), 
        new LiveAuthListener() {
               public void onAuthError(LiveAuthException exception, Object userState) {
                   resultTextView.setText("Error signing in: " + exception.getMessage());
               }
            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                try {
                    JSONObject body = new JSONObject();
                    body.put("x", 0.5);
                    body.put("y", 0.5);
                    JSONObject user = new JSONObject();
                    user.put("name", "Stig Struve-Christensen");
                    user.put("id", "a6b2a7e8f2515e5e");
                    body.put("user", user);
                       client.postAsync(tagsPath, body, opListener);    
                }
                catch(JSONException ex){
                    resultTextView.setText("Error creating tag: " + ex.getMessage());
                }
               }
        }
    );
}


[REST]

POST https://apis.live.net/v5.0/file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131/tags

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "user": {
            "name": "Stig Struve-Christensen",
            "id": "a6b2a7e8f2515e5f"
    },
    "x": 0.5, 
    "y": 0.5 
} 

In the preceding code, change the photo ID to a different photo ID, video ID, or audio ID, to add a tag to another photo or video.

For details about the required and optional structures that your app must provide to use POST, see the "Tag object" section in REST reference.

Top

 

 

Show:
© 2014 Microsoft