我正在使用Facebook查看使用此特定应用程序的所有朋友。分别重定向到他们的Facebook页面。单击时,我想重定向到Facebook页面以外的其他链接。是否可以 ?如何?
我的代码是
<script>
FB.init({
appId : '********', //App ID
channelUrl : 'http://www.***.in/', // Channel File
status : true,
cookie : true,
xfbml : true
});
FB.getLoginStatus(function(response) {
if (response.session) {
globaluserid=response.session["uid"];
//fetching friends uids from 'friend' table. We are using FB.api syntax
FB.api(
{
method: 'fql.query',
query: 'SELECT uid1 FROM friend WHERE uid2='+globaluserid
},
function(response) {
//once we get the response of above select query we are going to parse them
for(i=0;i<response.length;i++)
{
//fetching name and square profile photo of each friends
FB.api(
{
method: 'fql.query',
query: 'SELECT name,pic_square,username FROM user WHERE uid='+response[i].uid1
},
function(response) {
//creating img tag with src from response and title as friend's name
htmlcontent='<img src='+response[0].pic_square+' title='+response[0].name+' alt='+response[0].username+' />';
}
);
}
}
);
} else {
// no user session available, someone you dont know
top.location.href="../kfb_login.php";
}
});
</script>
<div class="just_trying">
<div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"> </div> </div>
在您提供的代码样本中,您的fb.api实际上并没有用它检索到的信息做任何事情。您将其分配给htmlcontent
变量,但是您并没有使用此变量将内容注入到任何地方的HTML主体中。您看到的朋友照片列表来自登录按钮标签,data-show-faces="true"
表示登录按钮将显示一个由Facebook代码独家生成的脸部。
所以,您要将data-show-faces
设置为false并将JavaScript代码修改为:
function(response) {
//creating img tag with src from response and title as friend's name
htmlcontent = document.createElement('img');
htmlcontent.src = response[0].pic_square;
htmlcontent.title = response[0].name;
htmlcontent.alt = response[0].username;
document.getElementsByTagName('body')[0].appendChild(htmlcontent);
}
为简单起见,如果您使用的是jQuery,则将其修改为:
function(response) {
//creating img tag with src from response and title as friend's name
htmlcontent = '<img src='+response[0].pic_square+' title='+response[0].name+' alt='+response[0].username+' />'
$('body').append(htmlcontent);
}