0
我正在一個很棒的項目,通常我使用AS3,但現在我正在使用Javascript。無法獲取對象功能
我有以下信息:下面我試圖訪問檢測線,基本上我需要的是檢測(response.username)。我嘗試了很多東西,任何人都可以幫忙嗎?
<div id="fb-root"></div>
<script type="text/javascript">
$(document).ready(function(){
var appId = "121070974711874";
// If logging in as a Facebook canvas application use this URL.
var redirectUrl = "http://apps.facebook.com/bggressive";
// If logging in as a website do this. Be sure to add the host to your application's App Domain list.
var redirectUrl = window.location.href;
// If the user did not grant the app authorization go ahead and
// tell them that. Stop code execution.
if (0 <= window.location.href.indexOf ("error_reason"))
{
$(document.body).append ("<p>Authorization denied!</p>");
return;
}
// When the Facebook SDK script has finished loading init the
// SDK and then get the login status of the user. The status is
// reported in the handler.
window.fbAsyncInit = function(){
FB.init({
appId : appId,
status : true,
cookie : true,
oauth : true
});
FB.getLoginStatus (onCheckLoginStatus);
};
(function(d)
{
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
function onCheckLoginStatus (response)
{
if (response.status != "connected")
{
top.location.href = "https://www.facebook.com/dialog/oauth?client_id=" + appId + "&redirect_uri=" + encodeURIComponent (redirectUrl) + "&scope=user_photos,friends_photos";
}
else
{$
// Start the application (this is just demo code)!
$(document.body).append ;
FB.api('/me?fields=username', function(response) {
function detect(URL) {
var image = new Image();
image.src = URL;
image.onload = function() {
var result = 'result'; // An example result
}
document.body.appendChild(image)
}
detect("https://graph.facebook.com/" + response.username + "/picture?width=200&height=200");
});
FB.api('/me/friends?fields=id,first_name', function(response) {
var randomFriend = Math.floor(getRandom(0, response.data.length));
gFriendID = response.data[randomFriend].id;
var randomFriend = Math.floor(getRandom(0, response.data.length));
gFriendID2 = response.data[randomFriend].id;
function friend1(URL) {
var image = new Image();
image.src = URL;
image.onload = function() {
var result = 'result'; // An example result
}
document.body.appendChild(image)
}
friend1("https://graph.facebook.com/" + gFriendID + "/picture?width=200&height=200");
function friend2(URL) {
var image = new Image();
image.src = URL;
image.onload = function() {
var result = 'result'; // An example result
}
document.body.appendChild(image)
}
friend2("https://graph.facebook.com/" + gFriendID2 + "/picture?width=200&height=200");
});
}
}
});
</script>
嗨,沒有那是代碼的一部分,這是工作正常,我現在需要有用戶名基本上相同的驢行「detect()」,而不是 detect(「https:// graph.facebook.com/「+ response.username +」/ picture?width = 200&height = 200「); 我需要 detect(response.username); 我可以在這個代碼之外加載一個新函數或VAR –
好吧,對。在你的代碼中,'detect()'函數將一個url加載到一個圖像中。你想要這個其他檢測功能做什麼?我想它不應該將'response.username'加載到圖像對象的src'字段中? –
我只需要加載response.username,這樣我就可以使用它傳遞到此代碼之外的另一個函數 –