可以直接上传Base64编码图像,而无需使用Facebook PHP SDK 3.1.1保存?

$facebook->setFileUploadSupport(true);
$facebook->api('/me/photos', 'POST', array(
    'source' => '@/mycoolpic.png', // No need to use FS, base64 encoded image
    'message' => "I'm cool",
));
有帮助吗?

解决方案

不,不是我已经意识到或发现搜索。确保在图像名称周围使用realpath(),以给图像的绝对路径。

其他提示

您可以按照php进行以下操作:

function base64_to_jpeg( $base64_string, $output_file ) {
  $ifp = fopen( $output_file, "wb" ); 
  fwrite( $ifp, base64_decode( $base64_string) ); 
  fclose( $ifp ); 
  return( $output_file ); 
}
$facebook->setFileUploadSupport(true);
$image = base64_to_jpeg( $your_base64_string, 'tmp.jpg' );
$args = array('message' => 'Some message');
$args['image'] = '@' . realpath( $image );
$data = $facebook->api('/your_user_id/photos', 'post', $args);
unlink($image);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top