Facebook SDK with PHP - Image Link

0

I'm using the code below for an application for facebook, I'm having trouble posting the image with a link in the image, follow the code.

// Cria a instancia da aplicacao, informando o appid e o secret
$facebook = new Facebook(array(
'appId'  => APP_ID,
 'secret' => APP_SECRET,
));
// habilita suporte para upload de arquivos
$facebook->setFileUploadSupport(true);
// obtem o id do usuario
$user = $facebook->getUser();
if ($user) { // usuario logado
    try {

        // verificar permissao
        $permissions = $facebook->api("/me/permissions");

        $perms = [];
        foreach($permissions['data'] as $perm) {
            if($perm['status'] == 'granted') {
                $perms[] = $perm['permission'];
            }
        }

        // solicita a permissao ate que o usuario aceite para poder continuar
        if(!in_array('publish_actions', $perms)) {
            $loginUrl = $facebook->getLoginUrl(array('scope' => 'publish_actions, user_photos'));
            header("Location: " . $loginUrl);
            exit;
        }

        // publicar foto

        // dados para envio da publicacao da foto
        $post_data = array(
                "message" => "teste_" . time(),
                "image" => '@' . realpath("ok.jpg"), // localizacao da foto
        );

        // publica foto na timeline
        $data['photo'] = $facebook->api("/me/photos", "post", $post_data);
        echo "Foto publicada com sucesso!";

    } catch (FacebookApiException $e) {
            // tratamento de excecao
            echo($e);
            $user = null; }
} else {
    // usuario nao logado, solicitar autenticacao e permissão publish_actions
    $loginUrl = $facebook->getLoginUrl(array('scope' => 'publish_actions'));
    echo "<a href=\"$loginUrl\">Facebook Login</a><br />";
    echo "<strong><em>Voc&ecirc; n&atilde;o esta conectado..</em></strong>";
}
    
asked by anonymous 06.07.2016 / 23:44

1 answer

1

Henrique, The FB documentation consists of

  $linkData = [
  'link' => 'http://www.example.com',
  'message' => 'User provided message',
  ];

See more information at link

I hope to have helped, hugs

    
24.08.2016 / 01:31