0

ユーザーのプロフィール写真を別の画像に配置したいので、次のコードでユーザーのプロフィール写真を取得してみました

$url='https://graph.facebook.com/'.$uid.'/picture?type=large';
$userpic = imagecreatefromjpeg($url);
imagejpeg($userpic, "xyz.jpg", 100);

しかし、私はこのエラーが発生しています:

imagecreatefromjpeg() [function.imagecreatefromjpeg]: Cannot read image data in /home/a3111484/public_html/fb/index.php

私も試しfile_get_contents()ましたが、その場合は空のjpgファイルが作成されます。

問題を理解するのを手伝ってください。

cURL の方法も試しましたが、次のエラーが発生しました。

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a3111484/public_html/fb/index.php on line 31
4

1 に答える 1

0

私はこれがあなたが必要とすることをすると思います:

<?php
$q = $_GET['q'];
$img = imagecreatefromstring(file_get_contents('https://graph.facebook.com/'.$q.'
   /picture?type=large'));
Header( "Content-type: image/jpeg");
imagejpeg($img);
imagedestroy($img);

これは私のサイトに として住んでいますfacebook_img.php

次のようなコードを使用してページに画像を追加するために使用します。

printf('<meta property="og:image" content="/path/to/facebook_img.php?q=%s" />', $fb_user_id);

id/picture@IMSoP: API エンドポイントが写真の URL への 301 リダイレクトを返すため、このような複雑な処理を行う必要があります。

于 2012-08-18T17:07:37.717 に答える