I am using mailchimp's webhook feature to (eventually) run a script on my app that will mark a user as unsubscribed from the newsletter if they unsubscribe through mailchimp.
Mailchimp is passing the following array to my script using POST.
Array
(
[type] => unsubscribe
[fired_at] => 2014-01-12 12:56:23
[data] => Array
(
[action] => unsub
[reason] => manual
[id] => 1b3a2f11af
[email] => email#domain.com
[email_type] => html
[ip_opt] => xxx.xxx.xxx.xxx
[web_id] => 128403001
[merges] => Array
(
[EMAIL] => email#domain.com
[FNAME] => FNAME
[LNAME] => LNAME
)
[list_id] => 5c30250cdb
)
)
My issue is, how can I get the [email] value out of it so that I can then pass that as a variable to update the database?
$email = $_POST ['data']['email'];
Try this code:
$result_array = $_POST;
echo $result_array["data"]["email"]; // or $_POST["data"]["email"];
Related
Here i am having one multidimensional array , using this array i want to take from emails array i want to take user email value like abc#gmail.com and from name array i want to take value givenName like Raju and from image array i want to take url like www.domain.com
print_r($user_info);
Array
(
[kind] => plus#person
[etag] => "EhMivDE25UysA1M2v-A/ZXQsxHAN9QSz-hQoXfQGzFyLWdQ"
[gender] => male
[emails] => Array
(
[0] => Array
(
[value] => abc#gmail.com
[type] => account
)
)
[objectType] => person
[id] => 100776010499118027035
[displayName] => Raju r
[name] => Array
(
[familyName] => r
[givenName] => Raju
)
[url] => https://plus.google.com/100776010499118027035
[image] => Array
(
[url] => www.domain.com
[isDefault] =>
)
[isPlusUser] => 1
[language] => en
[circledByCount] => 1
[verified] =>
[domain] => www.facebook.com
)
Expected Results
abc#gmail.com
Raju
www.domain.com
I tried like this
foreach($user_info['emails'] as $result){
$user_email = $result['value'];
foreach($result['name'] as $nameresult){
$user_name = $nameresult['givenName'];
}
}
Seems name does not seems to be an array of arrays like emails. So you can directly take that name instead of inner loop
foreach($user_info['emails'] as $result){
$user_email = $result['value'];
}
In this it the email value will be overridden each time and will hold only last email element value.
&
$user_info['name']['familyName'];
$user_info['image']['url'];
What I understand from the above set of data is that a user will have multiple email ids and a one and one image url. So above logic works.
I'm using Directory API with PHP to retrieve all users.
A response for a user who has a phone number added looks like this:
Google_Service_Directory_User Object ( [collection_key:protected] =>
nonEditableAliases [addresses] => [agreedToTerms] => 1 [aliases] =>
[changePasswordAtNextLogin] => [creationTime] =>
2016-11-29T14:21:30.000Z [customSchemas] => [customerId] => 1234
[deletionTime] => [emails] => Array ( [0] => Array ( [address] =>
test#companymail.com [primary] => 1 ) [1] => Array ( [address] =>
test#companymail.com ) ) [etag] => "tagg" [externalIds] =>
[hashFunction] => [id] => 12344 [ims] => [includeInGlobalAddressList]
=> 1 [ipWhitelisted] => [isAdmin] => [isDelegatedAdmin] => 1 [isMailboxSetup] => 1 [kind] => admin#directory#user [lastLoginTime]
=> 2016-12-12T10:13:31.000Z [nameType:protected] => Google_Service_Directory_UserName [nameDataType:protected] =>
[nonEditableAliases] => Array ( [0] =>
test#companymail.com.test-google-a.com [1] => test#companymail.com )
[notes] => [orgUnitPath] => / [organizations] => [password] =>
[phones] => [primaryEmail] => test#companymail.com [relations] => [suspended] => [suspensionReason] => [thumbnailPhotoEtag] =>
[thumbnailPhotoUrl] => [websites] =>
[internal_gapi_mappings:protected] => Array ( ) [modelData:protected]
=> Array ( [name] => Array ( [givenName] => TestNAme [familyName] => TestNAme [fullName] => TestNAme TestNAme ) ) [processed:protected] =>
Array ( ) )
The phone number was set 5 days ago (it's there), but as you can see the "phones" array is empty.
This is how I use the API:
$directory_service = new Google_Service_Directory($client);
$params = array('domain' => $domain);
$results = $directory_service->users->listUsers($params);
$users = $results->getUsers();
I can't figure out what's wrong. Do I need to enable any settings?
How can I get users' phone numbers?
Thanks in advance.
You might have added phone numbers for the domain contact but in your own contacts data. These will display 'merged' with the domain contact details in the Contacts UI and appear correct to you. They won't be visible to others though or be stored in the domain data.
Do this for testing:
Pick a domain user account and add a phone number for them using the admin console Users UI. Admin console > Users > (select User) > Account > Contact information > Edit > Add a phone > Click Update User.
To confirm your addition, use Try this API here: https://developers.google.com/admin-sdk/directory/v1/reference/users/get and just enter your user account name from 1 (email address) in userKey, for viewType select admin_view and click Execute.
You should see the phone data in the JSON returned. Once you can do this you can retest your PHP code.
I have made a simple facebook register widget.
On register the App sends the data to send.php
On send.php I have
print_r($response);
And I get something like this:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1367953200
[issued_at] => 1367946138
[oauth_token] => BAAE0refKufgBAORkK7hUaVpF8MnFygoqHAHrO3nRJMyNjvJx6RjiMjoqbz2YlfqeogcIPGJJaIgD0xtxhBj1WRgQ5F5SidjwM7ZCKOyZBlEuatIqIccbjGj2uMV5hqtKtZA1g7hOEqMeZAEwmnO6SgRgsb9ittKZCDnPfoxYxCxZAZBAhIKX457IG5ZB4yknv9FZB8QUG7Pt0mfBRQUYG12KoTmO7QRH20LP65FyPqTi7mAZDZD
[registration] => Array
(
[name] => derp derp
[email] => ddddd#gmail.com
[location] => Array
(
[name] => Vienna, Austria
[id] => 1.1116511224109E+14
)
[gender] => male
[phone] => sss
)
[registration_metadata] => Array
(
[fields] => [ {'name':'name'}, {'name':'email'}, {'name':'location'}, {'name':'gender'}, {'name':'phone', 'description':'Phone Number', 'type':'text'},]
)
[user] => Array
(
[country] => at
[locale] => en_US
)
[user_id] => 100000506481284
)
So the data gets passed without a problem but how can I access a specific value?
For example text book array stuff doesnt appear to be working like:
print $response[0];
Gives me an error:
Notice: Undefined offset: 0 in C:\xampp\htdocs\ddd\send.php on line 38
How else can I access the data?
For example how could I store country, email, name or whatever in their own variables so I can echo them later? Its there but I cant seem to figure out how to "digest" it properly with php.
There is no index 0 in the array you pasted..
Use it like
$email = $response['registration']['email'];
If it was an object instead of an array you would do
$email = $response->registration->email
This is very basic PHP array handling.
http://php.net/manual/en/language.types.array.php
I am trying to create a facebook signup. I am receiving the signed_request from facebook that is being decoded and displayed as the following:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 0
[issued_at] => **********
[oauth_token] => *******************************************************************************************************************
[registration] => Array
(
[name] => Darren West
[email] => dwest#madeup.com
[password] => IJ8sU10lw
)
[registration_metadata] => Array
(
[fields] => name,email,password
)
[user] => Array
(
[country] => us
[locale] => en_US
)
[user_id] => ***************
)
I want to add the three fields within the registration array to a hidden form and automatically submit it to another page for saving to the database.
My question is how do I extract the name, email, and password from the registration array and assign them to individual variables. I used the following, but I don't get a result:
print $response['registration']->password;
Any help would be greatly appreciated.
Many thanks,
neojakey
print $response['registration']['password'];
I have a csv file uploaded and data read into an array .The valid data is stored in the array
as associative array indexed from 0-4000 records
Array
(
[0] => Array
(
[uname] => uname1
[name] => fullname1
[email] => uname1#email.com
)
[1] => Array
(
[uname] => uname2
[name] => fullname2
[email] => uname2
)
[2] => Array
(
[uname] => uname3
[name] => fullname3
[email] => uname3#email
)
[3] => Array
(
[uname] => uname3
[name] => fullname3
[email] => uname3#email
)
..
...
[3999] => Array
(
[uname] => uname3
[name] => fullname3
[email] => uname3#email
)
)
How can i insert so many records because the $array is stored in variable when i click the submit the $array is reset to null.
How can I approach this without using database, any solution available?
Are you trying to say you're overflowing the 64KB limit of the <FORM> when you submit it? Make sure you're using method="POST" and encoding="multipart/form-data".
It's also possibly, but highly unlikely with 4000 records, that you're exceeding the post_max_size and upload_max_filesize parameters in your php.ini file. If you're secretly trying to post 50 million email addresses instead then that's likely your problem.
If that doesn't help, then you need to clarify what you're trying to accomplish, because we're left guessing. ;)