Sample code for 30+ languages & platforms
DataFlex

Create Google Photos Album

See more Google Photos Examples

Demonstrates how to create a Google Photos album.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vJson
Token    Handle hoJsonToken
    Handle hoHttp
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sId
    String sTitle
    String sProductUrl
    Boolean iIsWriteable
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Get the previously obtained access token.
    // See Get Google Photos Access Token.

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
    If (Not(IsComObjectCreated(hoJsonToken))) Begin
        Send CreateComObject of hoJsonToken
    End
    Get ComLoadFile Of hoJsonToken "qa_data/tokens/googlePhotos.json" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoJsonToken To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get ComStringOf Of hoJsonToken "access_token" To sTemp1
    Set ComAuthToken Of hoHttp To sTemp1

    // Create an album named "animals"
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "album.title" "animals" To iSuccess

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoResp to vResp
    Get ComHttpJson Of hoHttp "POST" "https://photoslibrary.googleapis.com/v1/albums" vJson "application/json" vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Show the response body.
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1

    // Examine the response status code.  Success is indicated by a status code of 200.
    Get ComStatusCode Of hoResp To iTemp1
    Showln "response status code: " iTemp1

    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoad Of hoJson sTemp1 To iSuccess

    // Sample response:

    // {
    //   "id": "AKcbugHaQTvUKSi3M2RQxOhxhdEaLc5mfUcqFoIU_kpQaROyUD70BcFt7_mnz5PcwwsjPKeKnLHN",
    //   "title": "animals",
    //   "productUrl": "https://photos.google.com/lr/album/AKcbugHaQTvUKSi3M2RQxOhxhdEaLc5mfUcqFoIU_kpQaROyUD70BcFt7_mnz5PcwwsjPKeKnLHN",
    //   "isWriteable": true
    // }

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    Get ComStringOf Of hoJson "id" To sId
    Get ComStringOf Of hoJson "title" To sTitle
    Get ComStringOf Of hoJson "productUrl" To sProductUrl
    Get ComBoolOf Of hoJson "isWriteable" To iIsWriteable

    Showln "id = " sId


End_Procedure