简体   繁体   English

如何使用Twitter API和data:image / gif; base64更新Twitter个人资料图片?

[英]How to update Twitter profile picture using twitter api and data:image/gif;base64?

iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg== iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs + 9AAAABGdBTUEAALGPC / xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV + IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9 // q1uH4TLzw4d6 + ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg ==

The above data is a picture in data:image/png;base64 format. 上面的数据是data:image/png;base64格式的图片。 Is it possible to update a twitter profile picture without providing the path to the image (like http://....com ) but instead by providing the image data in the format above? 是否可以在不提供图像路径(例如http://....com )的情况下而是通过以上述格式提供图像数据来更新Twitter个人资料图片?

Yes, it's documented https://dev.twitter.com/rest/reference/post/account/update_profile_image and https://dev.twitter.com/rest/reference/post/account/update_profile_background_image 是的,它已记录在https://dev.twitter.com/rest/reference/post/account/update_profile_imagehttps://dev.twitter.com/rest/reference/post/account/update_profile_background_image

Sending something via base64_encode(file_get_contents($image_path)))) will yield results. 通过base64_encode(file_get_contents($image_path))))发送东西会产生结果。 Make sure your file is <700kb and smaller than <1000px. 确保您的文件小于700kb,小于1000px。

Having had a quick look at the Twitter Documentation, specifically the section regarding Updating a User's Profile Image , it does not clearly state whether it will, or will not accept a Base64-encoded string for an image. 快速浏览了Twitter文档,特别是有关更新用户个人资料图像的部分之后 ,它并没有明确说明它是否会或不接受图像的Base64编码字符串。

That being said, I would presume that it would not (feel free to test it and see if it does, but, as a rule, if an API wants a URL as an input, it will only recognise a URL as valid). 话虽这么说,我认为它不会(可以随意测试并查看是否可以,但是,通常,如果API希望将URL作为输入,则它将仅将URL识别为有效)。

You could, of course, create a PHP script on your server, which, using the PHP function imagecreatefromstring() [ PHP Docs ] and then use that URI as the value for the Twitter API. 当然,您可以在服务器上创建一个PHP脚本,该脚本使用PHP函数imagecreatefromstring() [ PHP Docs ],然后将该URI用作Twitter API的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM