我在使用标记facebook API的功能时遇到问题,我将为您创建的应用程序摘要,以便您更好地了解我需要的内容。
我正在创建一个用户选择他的朋友的应用程序,该软件会生成一个包含所有朋友名称和每个标签的图像。
我成功完成了所有功能:列出朋友,选择他们,生成图像并发布到时间线。但我无法标记人物,这对应用程序的病毒效应起着重要作用。
发生了一件奇怪的事情,如果我启用沙盒模式并仅选择ADMINS或TESTERS,则代码可以正常工作。但是,如果我关闭沙盒模式并选择任何其他朋友,那么标签就不会发生任何事情。
下面我留下我用过的代码。 我使用array_push函数将ID添加到Facebook'标签'数组。
Facebook Conection:
// 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;
}
}
欢迎任何帮助,谢谢!