locked
How to add an image with the Twitter action " Post a tweet"? RRS feed

  • Question

  • The media is to be in a binary format according to the action documentation.


    How can I upload an Image with a tweet?

    Here is my action with the error response.


    Aaron Ralls

    Sunday, September 2, 2018 7:17 PM

Answers

  • Hello Aaron,

    You need to use the base64ToBinary function on the base64 data to convert it to the binary format and then it will be successfully accepted and posted by the twitter api.

    your code for the twitter connector should look like below.

    {
        "inputs": {
            "host": {
                "connection": {
                    "name": "@parameters('$connections')['twitter']['connectionId']"
                }
            },
            "method": "post",
            "body": "@base64ToBinary(triggerBody()?['imageData'])",
            "path": "/posttweet",
            "queries": {
                "tweetText": "@triggerBody()?['tweetText']"
            },
            "authentication": "@parameters('$authentication')"
        }
    }

    in above snippet, imageData is the node in which I tried passing the data to the Logic app and it is in base64 format.

    I tried replicating and solving the issue you can take a look at it here: Tweeting Using Logic Apps: Error “media type unrecognized” when sending image with Tweets


    Mandar Dharmadhikari


    Monday, September 3, 2018 2:26 AM

All replies

  • Hello Aaron,

    You need to use the base64ToBinary function on the base64 data to convert it to the binary format and then it will be successfully accepted and posted by the twitter api.

    your code for the twitter connector should look like below.

    {
        "inputs": {
            "host": {
                "connection": {
                    "name": "@parameters('$connections')['twitter']['connectionId']"
                }
            },
            "method": "post",
            "body": "@base64ToBinary(triggerBody()?['imageData'])",
            "path": "/posttweet",
            "queries": {
                "tweetText": "@triggerBody()?['tweetText']"
            },
            "authentication": "@parameters('$authentication')"
        }
    }

    in above snippet, imageData is the node in which I tried passing the data to the Logic app and it is in base64 format.

    I tried replicating and solving the issue you can take a look at it here: Tweeting Using Logic Apps: Error “media type unrecognized” when sending image with Tweets


    Mandar Dharmadhikari


    Monday, September 3, 2018 2:26 AM
  • The base64ToBinary() would not work since it has a limitation on the size of data you can pass in.

    What I ended up doing was have my Azure Function that builds my image return an application octet-stream and pass that directly to the media parameter<g class="gr_ gr_11 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="11" id="11">.</g>


    <g class="gr_ gr_11 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style replaceWithoutSep" data-gr-id="11" id="11">Aaron</g> Ralls



    • Edited by Aaron Ralls Friday, September 7, 2018 7:03 PM format
    Friday, September 7, 2018 7:01 PM