Graph Reference

GraphConnection class

All Graph operations are done with the GraphConnection class.

Script
Function

gkScript::GraphConnection()

Creates a class instance

GraphConnection offers the following features:

class GraphConnection
{
    // connection state
    bool isConnected();
    string getUserId();

    // Authentication
    string getAuthorizeUrl(string login_hint);
    string getResponseUrl();
    bool setAuthorizationResponse(string ResponseUrl);

    bool hasAdminScope();
    string getAdminConsentUrl();
    string getAdminResponseUrl();
    bool checkAdminConsentResponse(string ResponseUrl);

    // OneDrive
    class Drive
    {
        string id;

        string name;
        string description;
        string url;

        int64 sizeTotal, sizeFree;
        time_t created;
    };

    class DriveItem
    {
        string id;
        string driveId;

        bool isFolder;
        string name;
        string path;
        string downloadUrl;

        int64 size;
        time_t created, modified;
    };

    bool getPersonalDrive(Drive &);
    bool getDriveItem(DriveItem &, string driveId, string path);
    vector<DriveItem> getChildItems(DriveItem);
    bool createChildFolder(DriveItem &newFolder, DriveItem parent);
    bool renameMoveItem(DriveItem &, string newName, string newParentItemId);
    bool deleteItem(DriveItem);

    bool uploadFile(DriveItem &, DriveItem parent, string fileName, string localFilePath);
    bool uploadFile(DriveItem &, string localFilePath);
    bool uploadFile(DriveItem &, string localFilePath, string sessionUrl);

    bool setCallback(callbackObject);
};

OneDrive file operations

In order to work with OneDrive, you need a drive object.

Script
Function

GraphConnection::getPersonalDrive(Drive &)

Get the primary OneDrive assigned to the user

All further file operations work on DriveItems, which could be either folders or files.

Script
Function

GraphConnection:: getDriveItem(DriveItem &, string driveId, string path)

Opens a DriveItem. To open the root directory of a drive, use the path "/"

GraphConnection:: getChildItems(DriveItem &)

Get directory contents

List directory sample

Script
Function

GraphConnection::renameMoveItem(DriveItem &, string newName, string newParentItemId)

Rename and/or move DirectoryItems

GraphConnection::renameMoveItem(item, "newName", "")

Will rename item to "newName"

GraphConnection::renameMoveItem(item, "", folderXY.id)

Will move item to folderXY

GraphConnection::renameMoveItem(item, "newName", folderXY.id)

Will move and rename item.

Basic file operations sample

File upload

Script
Function

GraphConnection::uploadFile(DriveItem &, DriveItem parent, string fileName, string localFilePath)

Will upload new files

GraphConnection::uploadFile(DriveItem &, std::string localFilePath)

Will upload existing files

GraphConnection::uploadFile(DriveItem &, std::string localFilePath, std::string sessionUrl)

Will upload files with an externally generated Upload session

All upload methods overwrite existing content, and can use a callback object to report upload progress.

Script
Function

GraphConnection::setCallback(callbackObject)

Will set a callback object

File upload sample

Last updated

Was this helpful?