2012-11-03 69 views

回答

0

啊,這裏是你怎麼做:

function getFacebookInfo(){ 
    Titanium.Facebook.requestWithGraphPath('me', {}, 'GET', function(e){ 
     if (e.success){ 
      var jsonObject = JSON.parse(e.result); 
      //do something here with these values. They cannot be passed out of this 
      //function call... this is an asynchronous call 
      //that is, do this: 
      saveToDb(jsonObject.first_name); 
     } else { 
      //some sort of error message here i guess 
     } 
    }); 

}; 

最後,nameusername一起,檢查了其他變量的facebook頁面可以獲得 -

http://developers.facebook.com/docs/reference/api/

最後:請注意,這是一個回調,並且鈦實際上不會等待此通話完成。也就是說,任何聲明爲requestWithGraphPAth之後返回的結果都會返回立即返回,結果幾乎總是空的。

我想你可以做一個漂亮的循環,只是...循環,直到某些變量設置爲false。你可以在回調中將該變量設置爲false ...但這看起來很狡猾。

只是讓你回電話做一切別的,就是保存到數據庫等等等等

如果去調用Ti.Facebook.authorise的路線()登錄用戶,請記得在通話之前定義

Ti.Facebook.addEventListener('login',function(e){ 
    if (e.success){ 
... 
... 
    } else if (e.error){ } else if (e.cancel) { } 
} 

。然後,在成功的位置,你可以做一個requestWithGraphPath調用等等。我將所有細節保存到數據庫中,然後每次都檢索它們,對我來說工作正常!

0

我沒有測試的代碼,但你可以試試這個:

var fbuid = Titanium.Facebook.uid; //this would be the logged user's facebook uid 

function fQuery() //this function exec the fql query 
{ 
    var myQuery = "SELECT name FROM user WHERE uid = "+fbuid; 

    var data = []; 

    Titanium.Facebook.request('fql.query', {query: myQuery}, function(x) 
    { 
     var results = JSON.parse(x.result); 
     var username = results[0].name; //user's fb name 
    }); 
}; 
+0

HM,沒有 - 這是使用我們正在鼓勵「請求」呼叫不做 – bharal

+0

這是引用這樣的事情很好的做法。 –

+0

?你什麼意思? – bharal

1

您不需要執行任何操作,登錄完成後在數據響應中提供用戶名。

Look at the appcelerator documentation

+0

你是對的......但我使用授權,所以我需要定義一個處理程序等來處理這個。不過,+1指向正確的方向。 – bharal