jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
777 stars 235 forks source link

Upload media - base64 encoded image #205

Closed slangdog closed 7 years ago

slangdog commented 7 years ago

I want to post an image created using HTML Canvas to users timeline without first saving onto server. No problem getting the image string into the PHP script, but how would I go about converting it to use with media_upload method?

$reply = $cb->media_upload(array('media' => $image));

example of $image (truncated): data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArwAAAK8CAYAAAANumxDAAAgAElEQVR4Xuy9WbBl53UetvZwzrlz3+7b84juBtCYCBADCZIixUGkRMuaJSuRbMVxpKSkchQ/xHlJ5TGVl6TKL1Gq4li2S7YVR5GURBI1UDTFeQRBAmiggZ7R83jn8Zw9pL5vrbX3f849d+yGVE7cKhHd956z97//fw3f+tawo7xsl2VRyKo/USRRFK3+OX8S2/9GUopIyf/VP/hGJPi5/h9++9fxB/fU1ebb...

slangdog commented 7 years ago

I've tried replacing 'media' with 'media_data' in the array. Still get the same error:

string(22) "/1.1/media/upload.json" ["error"]=> string(24) "media type unrecognized."

slangdog commented 7 years ago

media_data accepts this: $image = str_replace('data:image/png;base64,', '', $image);