如何使用图形 API 设置 Facebook 个人资料图片 [英] how to set a facebook profile picture using the graph api

查看:45
本文介绍了如何使用图形 API 设置 Facebook 个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以使用graph api来改变用户的头像?

Is there any way to change the user's profile picture using the graph api?

我知道你不能使用其余的 api(参考),但我在新的图形 api 中找不到任何东西.

I know you can't with the rest api (reference), but I could not find anything in the new graph api.

推荐答案

使用 Graph API 将图片上传到现有相册(或创建一个新相册).看起来像这样:

Upload the picture to an existing album (or create a new one) using the Graph API. Will look something like this:

  $args = array('message' => 'Caption');
  $args['image'] = '@' . realpath("the_image.png");

  try {
    $data = $facebook->api('/'.$album_uid.'/photos', 'post', $args);
  }
  catch(Exception $e) {
    print "<pre>";
    print_r($e);
    print "</pre>";
  }

然后通过 Graph API 获取上传的图像并重定向到图像的链接,将 &makeprofile=1 添加到查询字符串.用户现在将被重定向到个人资料图片裁剪页面:

Then get the uploaded image via the Graph API and redirect to the image's link, add &makeprofile=1 to the querystring. The user will now be redirected to the profile image cropping page:

try {
  $pictue = $facebook->api('/'.$data['id']);
  header("Location: ".$pictue['link']."&makeprofile=1");
}
catch(Exception $e) {
  print "<pre>";
  print_r($e);
  print "</pre>";
}

这篇关于如何使用图形 API 设置 Facebook 个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆