1

我在标记 facebook API 的功能上遇到问题,我会总结一下我正在创建的应用程序,以便您更好地了解我需要什么。

我正在创建一个应用程序,用户可以在其中选择他的朋友,并且该软件会生成一张包含他所有朋友姓名以及每个人标签的图像。

我在所有功能上都取得了成功:列出朋友、选择他们、生成图像并发布到时间线。但是我不能标记人,这是应用程序病毒效应的一个重要功能。

发生了一件奇怪的事情,如果我启用沙盒模式并只选择 ADMINS 或 TESTERS,代码就可以工作。但是如果我关闭沙盒模式并选择任何其他朋友,标签就不会发生任何事情。

下面我留下我用过的代码。我使用 array_push 函数将 ID 添加到 Facebook 'tags' 数组中。

脸书连接:

// INSERE O HEADER
include('includes/header.php');

// CONNECT // CONFIGURAÇÕES 
require('facebook_sdk/src/facebook.php');

// CONEXÃO COM O FACEBOOK
$facebook = new Facebook(array(
  'appId' => 'XXXXXXXXX,
  'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
));

// PEGA SEU ID
$user = $facebook->getUser();


// FUNÇÕES QUE PEGA AS INFOS DO FACEBOOK
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me?fields=id,name,email,friends,photos,friends.fields(photos)');
    $input = $facebook->api('/me?fields=id,name,email,friends,photos,friends.fields(photos)');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}


// LINK PARA LOGOUT E REDIRECT SE FOR USUARIO
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
  header('Location: passo1.php');
}
?>            <div class="bt-face"><a href="" onClick="fbLogin(); return false;" target="_self"><img name="bt_face" id="bt_face" onMouseOver="formbaixo_ON('face');" onMouseOut="formbaixo_OFF('face');" src="images/bt-face.png" alt="Conectar no Facebook" /></a></div>
    </div>



    <!---------------- PHP / JAVA BUTTON FACEBOOK (SCOPE = PERMISSÕES)  ----------------->
    <div id="fb-root"></div>

    <script type="text/javascript">

        function fbLogin() {
            FB.login(function(response) {
                 if (response.session) {
                    //user is logged in, reload page
                    window.location.reload(true);
                  } else {
                    // user is not logged in
                  }
                }, { perms:'email,manage_friendlists,publish_stream,user_photos,friends_photos'} );
            }

                </script>

标记代码:

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $access_token = $facebook->getAccessToken();
    $timeline = $facebook->api('/me?link');
    $timeline_link = $timeline['link'];
    $input = $facebook->api('/me?fields=id,name,email,friends,photos,friends.fields(photos)');
    //At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
    $facebook->setFileUploadSupport(true);



$album = $facebook->api(array(
'query' => "SELECT object_id FROM album WHERE owner=me() AND name='Album name' AND can_upload=1",
'method' => 'fql.query',
    ));

if (isset($album[0]['object_id'])) $album_uid = $album[0]['object_id'];
else
{
 foreach ($albums[data] as $album) {
//Test if the current album name is already in facebook
if($album[name] == 'Album name'){
$album_uid = $album[id];

}
}

if(!$album_uid){ 


}

}

    //Upload a photo to album of ID...
    $photo_details = array(
        'message'=> 'Eu criei um time...'
);
    $file = $url_image; //'images/teste2.gif'; //Example image file


$args_tags = array();

    // RETIRA BARRAS DOS ARRAYS
    $parte = explode("//", $convocados);
    $conta = count($parte);

    // EXIBE
    $espacamento_linha = 20;
    $x_convocados = 0;
    $y_convocados = 0;
    $array_facebook_tag = '';

    for($i=0; $i < ($conta-1); $i++) {

        $explode_parte = explode("-", $parte[$i]);

        $nome = str_replace("_"," ", $explode_parte[0]);
        $id = $explode_parte[1];

        $x_jogador = $x_convocados;
        $y_jogador = $y_convocados + ($i * $espacamento_linha);

        array_push($args_tags, array('tag_uid' => $explode_parte[1], 'x' => $x_jogador, 'y' => $y_jogador));

    }
$args = array(

    'message' => 'Esse é o meu time dos sonhos. Crie o seu time ',
    'image' => '@' . realpath($file),
    'tags' => $args_tags,

);

    $upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $args);
} catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

欢迎任何帮助,谢谢!

4

0 回答 0