2010-02-02 87 views
0

請幫忙!我一直在努力解決這個錯誤好幾天,但我不能爲了我的生活而弄明白。我正在使用Facebook連接並使用其API方法users_getInfo獲取「contact_email」屬性。facebook connect api「無法使用字符串偏移量作爲數組」錯誤

問題是,當我執行這個PHP文件,我得到這個錯誤:「不能使用字符串偏移作爲數組在......」。這個錯誤專門引用了這行代碼:$ firstName = $ user_details [0] ['contact_email'];

我在想這是因爲user_getInfo方法沒有返回任何結果......但是,關於這一切的最荒謬的部分是,我可以執行下面的代碼連續幾十次成功沒有上面的錯誤,但隨即沒有任何更改任何代碼,我會突然遇到這個錯誤,在這種情況下,它會開始給我一個錯誤幾十次,然後再次沒有任何代碼更改,再次開始執行成功。

這種奇怪的行爲發生,無論我正在抓取的屬性..(contact_email,first_name,last_name等)。我正在運行PHP 5.2.11。有什麼我失蹤?

請幫忙!

include_once'site/fbconnect/config.php'; //定義了$ api_key和$ secret。 include_once'site/facebook-platform/client/facebook.php'; include_once'site/facebook-platform/client/facebook.php'; global $ api_key,$ secret; $ fb =新Facebook($ api_key,$ secret); $ fb-> require_login(); $ fb_user = $ fb-> get_loggedin_user(); ($ last_','first_name','contact_email'));}};}};}};
$ email = $ user_details [0] ['contact_email']; $ firstName = $ user_details [0] ['first_name']; $ lastName = $ user_details [0] ['last_name'];

回答

1

使用facebook php客戶端API我也收到該錯誤,但是我的錯誤與檢查用戶是否使用friends_areFriends php方法的朋友有關。

// $ results_array = $ facebook-> api_client-> friends_areFriends($ fb_user,$ selected_friend_uid); // $ answer = $ results_array [0] ['are_friends'];

當我將$ result分配給「不能使用字符串偏移量作爲數組」時,我會得到這個錯誤,而上面的friends_areFriends方法卻失敗了很多。我的解決方案是創建一個運行該代碼的for循環,然後使用php方法is_array()檢查$ answer是否爲數組,如果不是,則再次執行方法調用。我的循環在嘗試失敗之前進行了10次嘗試。最後,這個檢查嚴重降低了我的Facebook應用程序的性能。相反,我刪除了friends_areFriends api call alltogather,我的facebook應用程序性能又好又快。

如果結果不是數組,您可能可以實現一個類似的功能,允許方法重試自己。我認爲這個問題在Facebook的一面,有時它們被淹沒,並且請求沒有成功完成。我提醒你不要嘗試超過5次嘗試,因爲如果你做了一個永久的循環,請放心,他們會禁止你使用Facebook API來淹沒它,所以要小心。

相關問題