how to set a facebook profile picture using the graph api

后端 未结 5 1272
半阙折子戏
半阙折子戏 2020-11-27 13:00

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

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

5条回答
  •  情书的邮戳
    2020-11-27 13:24

    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 "
    ";
        print_r($e);
        print "
    "; }

    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 "
    ";
      print_r($e);
      print "
    "; }

提交回复
热议问题