2017-06-12 53 views
0

現在我正在使用PHP解析sdk,並試圖獲取所有用戶信息。PHP解析無法獲取用戶的電子郵件

$query = ParseUser::query(); 
    $objArray = $query->find(); 
    $data = array(); 
    print_r($objArray); 
    foreach ($objArray as $obj) { 
    $one['id'] = $obj->getObjectId(); 
    $one['displayName'] = $obj->displayName; 
    $one['email'] = $obj->email; 
    $data[]=$one; 
    } 

,這是print_r的結果

Array ([0] => Parse\ParseUser Object ([_sessionToken:protected] => [serverData:protected] => Array ([readreceipt] => YES [pushnotification] => YES [usernameFix] => jodydunn [displayName_lower] => jody dunn [displayName] => jody dunn [firstLaunch] => Yes [username] => [email protected] [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 23404642 [verifiedAccount] => 1) [operationSet:protected] => Array () [estimatedData:Parse\ParseObject:private] => Array ([readreceipt] => YES [pushnotification] => YES [usernameFix] => jodydunn [displayName_lower] => jody dunn [displayName] => jody dunn [firstLaunch] => Yes [username] => [email protected] [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 23404642 [verifiedAccount] => 1) [dataAvailability:Parse\ParseObject:private] => Array ([readreceipt] => 1 [pushnotification] => 1 [usernameFix] => 1 [displayName_lower] => 1 [displayName] => 1 [firstLaunch] => 1 [username] => 1 [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 1 [verifiedAccount] => 1) [className:Parse\ParseObject:private] => _User [objectId:Parse\ParseObject:private] => 97EIKQVlUW [createdAt:Parse\ParseObject:private] => DateTime Object ([date] => 2017-01-30 14:26:15.568000 [timezone_type] => 2 [timezone] => Z) [updatedAt:Parse\ParseObject:private] => DateTime Object ([date] => 2017-06-12 23:34:47.234000 [timezone_type] => 2 [timezone] => Z) [hasBeenFetched:Parse\ParseObject:private] => 1) [1] => Parse\ParseUser Object ([_sessionToken:protected] => [serverData:protected] => Array ([username] => [email protected] [displayName_lower] => tiago marques [usernameFix] => tiagomarques [displayName] => Tiago Marques [firstLaunch] => Yes [readreceipt] => YES [pushnotification] => YES [facebookId] => 1722892281374124 [qbUserID] => 23295999) [operationSet:protected] => Array () [estimatedData:Parse\ParseObject:private] => Array ([username] => [email protected] [displayName_lower] => tiago marques [usernameFix] => tiagomarques [displayName] => Tiago Marques [firstLaunch] => Yes [readreceipt] => YES [pushnotification] => YES [facebookId] => 1722892281374124 [qbUserID] => 23295999) [dataAvailability:Parse\ParseObject:private] => Array ([username] => 1 [displayName_lower] => 1 [usernameFix] => 1 [displayName] => 1 [firstLaunch] => 1 [readreceipt] => 1 [pushnotification] => 1 [facebookId] => 1 [qbUserID] => 1) [className:Parse\ParseObject:private] => _User [objectId:Parse\ParseObject:private] => nOsEiFmpLu [createdAt:Parse\ParseObject:private] => DateTime Object ([date] => 2017-01-27 16:11:18.737000 [timezone_type] => 2 [timezone] => Z) [updatedAt:Parse\ParseObject:private] => DateTime Object ([date] => 2017-01-27 16:11:37.865000 [timezone_type] => 2 [timezone] => Z) [hasBeenFetched:Parse\ParseObject:private] => 1) [2] => Parse\ParseUser Object ([_sessionToken:protected] => [serverData:protected] => Array ([displayName_lower] => jody dunn [firstLaunch] => Yes [displayName] => jody dunn [usernameFix] => jodydunn [username] => [email protected] [readreceipt] => YES [pushnotification] => YES [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 23158732 [verifiedAccount] => 1) [operationSet:protected] => Array () [estimatedData:Parse\ParseObject:private] => Array ([displayName_lower] => jody dunn [firstLaunch] => Yes [displayName] => jody dunn [usernameFix] => jodydunn [username] => [email protected] [readreceipt] => YES [pushnotification] => YES [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 23158732 [verifiedAccount] => 1) [dataAvailability:Parse\ParseObject:private] => Array ([displayName_lower] => 1 [firstLaunch] => 1 [displayName] => 1 [usernameFix] => 1 [username] => 1 [readreceipt] => 1 [pushnotification] => 1 [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 1 [verifiedAccount] => 1) [className:Parse\ParseObject:private] => _User [objectId:Parse\ParseObject:private] => VtvElOtqFQ [createdAt:Parse\ParseObject:private] => DateTime Object ([date] => 2017-01-24 11:47:08.461000 [timezone_type] => 2 [timezone] => Z) [updatedAt:Parse\ParseObject:private] => DateTime Object ([date] => 2017-06-12 23:34:24.014000 [timezone_type] => 2 [timezone] => Z) [hasBeenFetched:Parse\ParseObject:private] => 1) [3] => Parse\ParseUser Object ([_sessionToken:protected] => [serverData:protected] => Array ([displayName] => Jody dunn [pushnotification] => YES [readreceipt] => YES [username] => [email protected] [firstLaunch] => Yes [usernameFix] => jodydunn [displayName_lower] => jody dunn [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 22885014) [operationSet:protected] => Array () [estimatedData:Parse\ParseObject:private] => Array ([displayName] => Jody dunn [pushnotification] => YES [readreceipt] => YES [username] => [email protected] [firstLaunch] => Yes [usernameFix] => jodydunn [displayName_lower] => jody dunn [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 22885014) [dataAvailability:Parse\ParseObject:private] => Array ([displayName] => 1 [pushnotification] => 1 [readreceipt] => 1 [username] => 1 [firstLaunch] => 1 [usernameFix] => 1 [displayName_lower] => 1 [userAlreadyAutoFollowedFacebookFriends] => 1 [qbUserID] => 1) [className:Parse\ParseObject:private] => _User [objectId:Parse\ParseObject:private] => oBBU5lwrAk [createdAt:Parse\ParseObject:private] => DateTime Object ([date] => 2017-01-17 23:09:42.008000 [timezone_type] => 2 [timezone] => Z) [updatedAt:Parse\ParseObject:private] => DateTime Object ([date] => 2017-01-17 23:09:46.529000 [timezone_type] => 2 [timezone] => Z) [hasBeenFetched:Parse\ParseObject:private] => 1) 

這樣我就可以讓其他的領域,但沒有現有的電子郵件。

如何獲得電子郵件。請告訴我。

+0

'print_r($ objArray);'?的輸出是什麼? – Enstage

+0

dunno試試'$ one ['email'] = $ obj-> get('email');',瘋狂的來源https://hotexamples.com/examples/parse/ParseUser/query/php-parseuser-query- method-examples.html –

+0

謝謝@Enstage我在我的帖子 – Alex

回答

0

你正在尋找的電子郵件屬性是一個可選的財產ParseUser一個實例。假設它在那裏,你應該檢查它是否存在。

如果您在註冊時採取的唯一必填字段是密碼用戶名。如果事先沒有提供並設置電子郵件(例如通過$user->setEmail('...')),則以後將不會有任何電子郵件訪問。

這就是說用戶名財產是你有一個有效的電子郵件用戶的下一個最好的選擇,假設他們用電子郵件註冊爲用戶名。除此之外,您可以始終要求您的用戶在註冊期間提交電子郵件,或者要求用戶名是電子郵件(這非常好用!)。

+0

謝謝@montymxb,正如你所說,我沒有做過(如$ user-> setEmail('...'))事先。但在Parse Dashboard用戶表中,現有一個'email'字段。所以我想我可以得到那個'email'字段值。 – Alex

+0

是的,你是正確的,'_User'類有一個註冊的** email **字段。但是,如果沒有設置電子郵件,默認值爲'null'。您可以通過調用'$ obj-> has('field-name');'來檢查'ParseObject'是否具有給定字段的數據。 – montymxb

0

電子郵件字段確實存在,您只需要使用masterKey即可獲取它。 使用$query->find(true);並提供masterKey與ParseClient::initialize,你應該得到的電子郵件。