简体   繁体   English

用imagepng上传Facebook API照片

[英]Facebook API photo uploading with imagepng

I have a quiz application on Facebook. 我在Facebook上有一个测验应用程序。 It uploads a photo to user's photos at the end of the quiz. 测验结束时,它将照片上传到用户的照片。

$photo_upload = $facebook->api('/me/photos', 'POST', array(
                                                'source' => '@' . './images/userimg.png',
                                                'message' => $message,
                                                )
                                            );

But it is a sample image, the same for everyone. 但这是示例图像,每个人都一样。 I want to make it personal by writing the user's name on the image. 我想通过在图像上写下用户名来使其个性化。 Part of create-img.php : create-img.php的一部分

try {
    $user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e) {
            error_log($e);
            $user_id = null; }

$username = iconv("UTF-8", "ISO-8859-2", $user_profile['name']);

$text = iconv("ISO-8859-2", "UTF-8", "Hello ". $username);

...

header('Content-type: image/png') ;

            ImagePNG($image) ;

            ImageDestroy($image) ;

            imagepng($image, "./images/imgs_to_post/sample_userimg.png");

            exit ;

It can be included in HTML, works fine, the image shows up with the user's name. 可以将其包含在HTML中,效果很好,并显示带有用户名的图像。

<img src="create-img.php" alt="" />

But when I try to put create-img.php as source in the API call above, i get an error. 但是,当我尝试将create-img.php用作上述API调用中的源代码时,出现错误。

Fatal error: Uncaught OAuthException: (#1) An unknown error occurred thrown in /home/mmdesign/public_html/.../php-sdk/base_facebook.php on line 1128

How can I put the result image of imagepng in the API call as source? 如何将imagepng的结果图像作为源放入API调用中?

Thank you in advance. 先感谢您。

But when I try to put create-img.php as source in the API call above, i get an error. 但是,当我尝试将create-img.php用作上述API调用中的源代码时,出现错误。

Of course, because that file contains PHP code, not image data. 当然,因为该文件包含PHP代码,而不包含图像数据。 (If you think the PHP code is parsed at this point, you're wrong.) (如果您认为此时已解析了PHP代码,那是错误的。)

Write the image to HDD first, and then feed the API the path to that image. 首先将图像写入HDD,然后将图像的路径输入API。

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

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