Search code examples
twittercoldfusioncfc

Posting Multiple Images to Twitter with Coldfusion using MonkehTweet


I am using MonkehTweet Coldfusion wrapper for Twitter Authentication. I have everything up working, but i cannot get my head around posting multiple images using the PostUpdateWithMedia function. I am relatively new to coldfusion, and learning it along the way. A simple call to PostUpdateWithMedia(status="", media="") would post to Twitter with an image, but how can i use this to post multiple images. The PostUpdateWithMedia function from MonkehTweet is,

    <cffunction name="postUpdateWithMedia" access="public" output="false" hint="Updates the authenticating user's status. Request must be a POST.  A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.">
    <cfargument name="status"                   required="true"     type="String"                   hint="The text of your status update. URL encode as necessary. Statuses over 140 characters will be forceably truncated." />
    <cfargument name="media"                    required="true"     type="string"                   hint="Up to max_media_per_upload files may be specified in the request, each named media[]. Supported image formats are PNG, JPG and GIF. Animated GIFs are not supported." />
    <cfargument name="possibly_sensitive"       required="false"    type="boolean"  default="false" hint="Set to true for content which may not be suitable for every audience." />
    <cfargument name="in_reply_to_status_id"    required="false"    type="String"                   hint="The ID of an existing status that the update is in reply to." />
    <cfargument name="lat"                      required="false"    type="String"                   hint="The location's latitude that this tweet refers to." />
    <cfargument name="long"                     required="false"    type="String"                   hint="The location's longitude that this tweet refers to." />
    <cfargument name="place_id"                 required="false"    type="String"                   hint="A place in the world. These IDs can be retrieved from geo/reverse_geocode." />
    <cfargument name="display_coordinates"      required="false"    type="String"                   hint="Whether or not to put a pin on the exact coordinates a tweet has been sent from." />
    <cfargument name="checkHeader"              required="false"    type="boolean"  default="false" hint="If set to true, I will abort the request and return the response headers for debugging." />
    <cfargument name="timeout" required="false" type="string" default="#variables.instance.timeout#" hint="An optional timeout value, in seconds, that is the maximum time the cfhttp requests can take. If the time-out passes without a response, ColdFusion considers the request to have failed." />
        <cfset var strTwitterMethod = '' />
            <cfset arguments["media[]"] = arguments.media />
            <cfset structDelete(arguments,'media') />
            <cfset strTwitterMethod = getCorrectEndpoint('api') & 'statuses/update_with_media.json' />
    <cfreturn genericAuthenticationMethod(timeout=getTimeout(), httpURL=strTwitterMethod,httpMethod='POST', parameters=arguments, checkHeader=arguments.checkHeader) />
</cffunction>

I have tried passing in multiple files as, PostUpdateWithMedia(status="", media="", media=""); but it didnot work. But, I am passing in the multiple media arguments wrong. Can someone help me with how to pass in multiple media arguments.


Solution

  • Unfortunately, MonkehTweet does not include support for the Twitter API media/upload endpoint, which is required for multi-image Tweets - it only supports the deprecated statuses/update_with_media, which still works, but only supports a single image. I also noticed that the code still refers to 140 character Tweets, so it probably has not been updated for some time. I'm not aware of an alternative ColdFusion wrapper for the API, either, so this is something you would need to build for yourself.