简体   繁体   English

登录后添加Facebook个人资料图片?

[英]Add Facebook Profile Picture after Login?

Here is my code:: 这是我的代码:

//if user is logged in - do this
function login() {
FB.api('/me', function(response) {  
document.getElementById('fb-info-block').innerHTML = 
"Welcome, " + response.name + ".<br /><br />" +
"<fb:like href = 'www.whitbreaddesign.com' show_faces = 'false' width = '100' action = 'like' colorscheme = 'light'></fb:like>";
});
}

Can someone tell me how to add the users facebook profile within this code...I already figured out how to retrieve their name with "Welcome, "+ response.name+" 有人可以告诉我如何在此代码中添加用户的Facebook个人资料吗...我已经想出了如何使用“欢迎,“ + response.name +”

Any ideas..thanks a bunch... 任何想法..谢谢一堆...

document.getElementById('something').innerHTML = '<img src="http://graph.facebook.com/' + response.id + '/picture" />';

You need to list fields you are interested in as a second parameter to FP.api: 您需要列出您感兴趣的字段作为FP.api的第二个参数:

FB.api("/me", {fields: "id,name,picture"}, function(response) {
    console.log(response.id, response.name, response.picture);
});

Here is a list of all available fields 这是所有可用字段的列表

您应该使用“ me.id”而不是“ response.id”:

  document.getElementById('something').innerHTML = '<img src="http://graph.facebook.com/' + me.id + '/picture" />';

You could use the FBML tag for profile pics: 您可以将FBML标签用于个人资料照片:

var profile_pic_html = '<fb:profile-pic></fb:profile-pic>';

Just add that anywhere on the page, and as long as you have FB Connect's xd_receiver setup, that will show the currently logged in user's profile pic. 只要将其添加到页面上的任意位置,只要您具有FB Connect的xd_receiver设置,它就会显示当前登录的用户的个人资料图片。 To show profile pics by UID use: 要通过UID显示个人资料图片,请使用:

var profile_pic_html = '<fb:profile-pic uid="'+some_uid+'" ></fb:profile-pic>';

You need to call FB.XFBML.Parse() so that your updated FBML can be parsed into HTML by facebook's javascript. 您需要调用FB.XFBML.Parse(),以便Facebook的JavaScript可以将更新后的FBML解析为HTML。 You may be missing that. 您可能会错过。

Maybe just use XFBML?: 也许只使用XFBML ?:

<fb:name uid="loggedinuser" use-you="no"></fb:name>
<fb:profile-pic uid="loggedinuser" size="square" facebook-logo="true"></fb:profile-pic>

Here's an example: http://fbrell.com/xfbml/account-info 这是一个示例: http : //fbrell.com/xfbml/account-info

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM