in witch mode a can read the email subject with php api ?
i do this code
// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Gmail($client);
// Print the labels in the user's account.
$user = 'me';
$results = $service->users_messages->listUsersMessages($user);
foreach($results as $mail){
$optParamsGet['format'] = 'metadata'; // Display message in payload
$message = $service->users_messages->get($user, $mail['id'],$optParamsGet);
$objMessage = $message->getPayload();
print_r($objMessage[18]['value']);
}
i find very difficult use this api with php because there isn't any documentation about the function.
where i can find the comple documentation?
(for example i found getPayload function because i see some example here)
thanks
If you have a look at a bare bones response you get when accessing the API with regular http-requests, I think a lot of things will be more clear.
I will list my latest message, and then get the message, and have a look at the response:
Request
maxResults = 1
GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1
Response
{
"messages": [
{
"id": "150791be31ee4e7b",
"threadId": "150791be31ee4e7b"
}
],
"nextPageToken": "05858850367051193217",
"resultSizeEstimate": 2
}
Request
GET https://www.googleapis.com/gmail/v1/users/me/messages/150791be31ee4e7b
Response
{
"id": "150791be31ee4e7b",
"threadId": "150791be31ee4e7b",
"labelIds": [
"INBOX",
"CATEGORY_SOCIAL",
"UNREAD"
],
"snippet": "Infinite Elgintensity has uploaded Gym Idiots - The Smith Machine's Retarded Cousin I have no",
"historyId": "623043",
"internalDate": "1445140881000",
"payload": {
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Delivered-To",
"value": "emtholin#gmail.com"
},
{
"name": "Received",
"value": "by 10.28.188.5 with SMTP id m5csp628249wmf; Sat, 17 Oct 2015 21:01:22 -0700 (PDT)"
},
{
"name": "X-Received",
"value": "by 10.182.28.74 with SMTP id z10mr15179312obg.80.1445140882358; Sat, 17 Oct 2015 21:01:22 -0700 (PDT)"
},
{
"name": "Return-Path",
"value": "<3kRkjVgcLDAgvwzmxt66w212jm.kwu1p2ttmB-898Fxiom0.xt20owwotm.kwu#youtube-subscriptions.bounces.google.com>"
},
{
"name": "Received",
"value": "from mail-ob0-x245.google.com (mail-ob0-x245.google.com. [2607:f8b0:4003:c01::245]) by mx.google.com with ESMTPS id l8si12292524oej.1.2015.10.17.21.01.22 for <emtholin#gmail.com> (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Oct 2015 21:01:22 -0700 (PDT)"
},
{
"name": "Received-SPF",
"value": "pass (google.com: domain of 3kRkjVgcLDAgvwzmxt66w212jm.kwu1p2ttmB-898Fxiom0.xt20owwotm.kwu#youtube-subscriptions.bounces.google.com designates 2607:f8b0:4003:c01::245 as permitted sender) client-ip=2607:f8b0:4003:c01::245;"
},
{
"name": "Authentication-Results",
"value": "mx.google.com; spf=pass (google.com: domain of 3kRkjVgcLDAgvwzmxt66w212jm.kwu1p2ttmB-898Fxiom0.xt20owwotm.kwu#youtube-subscriptions.bounces.google.com designates 2607:f8b0:4003:c01::245 as permitted sender) smtp.mailfrom=3kRkjVgcLDAgvwzmxt66w212jm.kwu1p2ttmB-898Fxiom0.xt20owwotm.kwu#youtube-subscriptions.bounces.google.com; dkim=pass header.i=#youtube.com; dmarc=pass (p=QUARANTINE dis=NONE) header.from=youtube.com"
},
{
"name": "Received",
"value": "by mail-ob0-x245.google.com with SMTP id da8so130023858obb.1 for <emtholin#gmail.com>; Sat, 17 Oct 2015 21:01:22 -0700 (PDT)"
},
{
"name": "X-Received",
"value": "by 10.107.148.204 with SMTP id w195mr21311032iod.15.1445140881929; Sat, 17 Oct 2015 21:01:21 -0700 (PDT)"
},
{
"name": "X-Received",
"value": "by 10.140.238.83 with SMTP id j80mr20061780qhc.2.1445140881732; Sat, 17 Oct 2015 21:01:21 -0700 (PDT)"
},
{
"name": "Return-Path",
"value": "<3kRkjVgcLDAgvwzmxt66w212jm.kwu1p2ttmB-898Fxiom0.xt20owwotm.kwu#youtube-subscriptions.bounces.google.com>"
},
{
"name": "Received",
"value": "from mail-pa0-f72.google.com (mail-pa0-f72.google.com. [209.85.220.72]) by gmr-mx.google.com with ESMTPS id wl2si2608966pab.1.2015.10.17.21.01.21 for <thulle3-0107#pages.plusgoogle.com> (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Oct 2015 21:01:21 -0700 (PDT)"
},
{
"name": "Received-SPF",
"value": "pass (google.com: domain of 3kRkjVgcLDAgvwzmxt66w212jm.kwu1p2ttmB-898Fxiom0.xt20owwotm.kwu#youtube-subscriptions.bounces.google.com designates 209.85.220.72 as permitted sender) client-ip=209.85.220.72;"
},
{
"name": "Received",
"value": "by mail-pa0-f72.google.com with SMTP id da3so25pad.2 for <thulle3-0107#pages.plusgoogle.com>; Sat, 17 Oct 2015 21:01:21 -0700 (PDT)"
},
{
"name": "DKIM-Signature",
"value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=youtube.com; s=20120806; h=mime-version:message-id:date:subject:from:to:content-type; bh=dxXkvZ79qLn59RVfXz4QAs5AW2+MyxrsrN55S+jKtK0=; b=mrrriloHJkEy4TT3wpzhEO1nvinpewLWHHExGGprhWlUU+5ME9M8w3xlaTeDcm0V0y QYDbH6TTG2rc0vwiLuZ46Dgm3rDC0brbg/Bdh3TQRUBneOTdAW4oMMs48DSIBbbFa58j U7GHaaXGNtsY3ah4D2x8Bv9XxPbtN1YoMEV+DFlYAStrIyyUiGXk7yotcBWqbB89/MFt ga9f+5Rhf38/TggWLRD88fBp8u2EIDB5VwqHsX5IstX2+Y0yb+yf4sk9iiToAnIXZhiC Ngqp3YdgLrI6+UlAvixbdB42nlxsGbBJ9WoF4dejLEIeQps47loxNuA2hBsiO1wqSE6n 3XYA=="
},
{
"name": "MIME-Version",
"value": "1.0"
},
{
"name": "X-Received",
"value": "by 10.66.182.162 with SMTP id ef2mr20318738pac.35.1445140881616; Sat, 17 Oct 2015 21:01:21 -0700 (PDT)"
},
{
"name": "X-No-Auto-Attachment",
"value": "1"
},
{
"name": "Message-ID",
"value": "<047d7bd6aa64e62f22052259149a#google.com>"
},
{
"name": "Date",
"value": "Sun, 18 Oct 2015 04:01:21 +0000"
},
{
"name": "Subject",
"value": "Infinite Elgintensity just uploaded a video"
},
{
"name": "From",
"value": "YouTube <noreply#youtube.com>"
},
{
"name": "To",
"value": "thulle3-0107#pages.plusgoogle.com"
},
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=047d7bd6aa64e62f000522591497"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=UTF-8; format=flowed; delsp=yes"
}
],
"body": {
"size": 301,
"data": "SW5maW5pdGUgRWx..."
}
},
{
"partId": "1",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 16884,
"data": "DQo8aHRtbCBsYW5nPSJl..."
}
}
]
},
"sizeEstimate": 22314
}
This is how a typical message will look, and all that the various libraries does is to make it easier to work with. The headers will reside inside of the payload, and it's the Subject-header you are looking for.
There is no function for getting a specific header, but it's not that hard to implement:
function getHeader($headers, $name) {
foreach($headers as $header) {
if($header['name'] == $name) {
return $header['value'];
}
}
}
$results = $service->users_messages->listUsersMessages($user);
foreach($results as $mail){
$message = $service->users_messages->get($user, $mail['id']);
$headers = $message->getPayload()->getHeaders();
$subject = getHeader($headers, 'Subject');
}
this works for me
$message = $service->users_messages->get($userId, $messageId,['format' => 'metadata', 'metadataHeaders' => ['From']]);
$headers = $message->getPayload()->getHeaders();
$from = $headers[0]['value']);
if($form == "My From")
....
I was working an mixed 2 or 3 examples and this is the result, in this case i need de Form metadata, change it for Subject and done.
Here is how I read the subject of the emails
$messages = $service->users_messages->listUsersMessages($user, ['q'=> 'from:foo#bar.com ']);
foreach ($messages->getMessages() as $mail)
{
$message = $service->users_messages->get($user, $mail->getId());
$headers = $message->getPayload()->getHeaders();
$subject = array_values(array_filter($headers, function($k){
return $k['name'] == 'Subject';
}));
printf("- %s\n", $subject[0]->getValue());
}
Related
This question already has answers here:
Cookies on localhost with explicit domain
(24 answers)
Closed 5 years ago.
I have an application that uses saml authentication and passes the response back via a cookie to the return URL the SP provides. The php code looks like this
setcookie('auth', $cred, time() + 30, parse_url($location, PHP_URL_HOST));
error_log($_COOKIE['auth']);
header('Location: ' . $location, true, 303);
die();
The redirect works fine but the cookie is not set. This is confirmed both in php as shown above, and in my application using document.cookies
I've exported the HAR to view the request and it actually looks like the cookie is being set, but it's still not accessible via document.cookie. The way it is supposed to work is that the application changes the window.location to the php file that authenticates, sets the cookie and redirects to the return parameter. Judging by the fact that the request is sent with the cookie, I'd guess that it is being set, but I can't seem to access it.
{
"startedDateTime": "2017-10-27T18:05:36.538Z",
"time": 271.7059999888301,
"request": {
"method": "GET",
"url": "https://supportworkslab.sw.test/sw/selfservice/sso/saml_auth.php?wssinstance=selfservice&returnto=http%3A%2F%2Flocalhost%2Fsw%2Fselfservice",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate, br"
},
{
"name": "Host",
"value": "supportworkslab.sw.test"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.9"
},
{
"name": "Upgrade-Insecure-Requests",
"value": "1"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36"
},
{
"name": "Accept",
"value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
},
{
"name": "Referer",
"value": "http://localhost/sw/selfservice/"
},
{
"name": "Cookie",
"value": "auth=eyJzdWNjZXNzIjoiQXV0aGVudGljYXRpb24gc3VjY2VzcyEiLCJjdXN0aWQiOiJhbGFuYyIsInNlc3Npb25JZCI6IjU5ZjM2MGRjLTBhOTI5NWFlLTQxYzEiLCJ3ZWJGbGFncyI6IjIxNDc0ODk1NTEiLCJjYWxsQ2xhc3MiOiJJbmNpZGVudCIsImFzc2lnbkdyb3VwIjoiU1VQUE9SVCIsImFzc2lnbkFuYWx5c3QiOiIifQ%3D%3D; SimpleSAMLAuthToken=_04a2be772f96fad7c5e2452846c05df5cbd570305e; SimpleSAML=62d6b2ebea7f66b0360a328dcb4f77a7; PHPSESSID=k9hpb09i3omt43bv7gireeuid0"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "Cache-Control",
"value": "no-cache"
}
],
"queryString": [
{
"name": "wssinstance",
"value": "selfservice"
},
{
"name": "returnto",
"value": "http%3A%2F%2Flocalhost%2Fsw%2Fselfservice"
}
],
"cookies": [
{
"name": "auth",
"value": "eyJzdWNjZXNzIjoiQXV0aGVudGljYXRpb24gc3VjY2VzcyEiLCJjdXN0aWQiOiJhbGFuYyIsInNlc3Npb25JZCI6IjU5ZjM2MGRjLTBhOTI5NWFlLTQxYzEiLCJ3ZWJGbGFncyI6IjIxNDc0ODk1NTEiLCJjYWxsQ2xhc3MiOiJJbmNpZGVudCIsImFzc2lnbkdyb3VwIjoiU1VQUE9SVCIsImFzc2lnbkFuYWx5c3QiOiIifQ%3D%3D",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "SimpleSAMLAuthToken",
"value": "_04a2be772f96fad7c5e2452846c05df5cbd570305e",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "SimpleSAML",
"value": "62d6b2ebea7f66b0360a328dcb4f77a7",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "PHPSESSID",
"value": "k9hpb09i3omt43bv7gireeuid0",
"expires": null,
"httpOnly": false,
"secure": false
}
],
"headersSize": 996,
"bodySize": 0
},
"response": {
"status": 303,
"statusText": "See Other",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Date",
"value": "Fri, 27 Oct 2017 18:05:36 GMT"
},
{
"name": "Server",
"value": "Apache"
},
{
"name": "Content-Type",
"value": "text/html"
},
{
"name": "Location",
"value": "http://localhost/sw/selfservice"
},
{
"name": "Set-Cookie",
"value": "SimpleSAML=62d6b2ebea7f66b0360a328dcb4f77a7; path=/; HttpOnly"
},
{
"name": "Set-Cookie",
"value": "PHPSESSID=k9hpb09i3omt43bv7gireeuid0; path=/; HttpOnly"
},
{
"name": "Set-Cookie",
"value": "auth=eyJzdWNjZXNzIjoiQXV0aGVudGljYXRpb24gc3VjY2VzcyEiLCJjdXN0aWQiOiJhbGFuYyIsInNlc3Npb25JZCI6IjU5ZjM3NTcwLTBhZTJmNzAzLTNmMTIiLCJ3ZWJGbGFncyI6IjIxNDc0ODk1NTEiLCJjYWxsQ2xhc3MiOiJJbmNpZGVudCIsImFzc2lnbkdyb3VwIjoiU1VQUE9SVCIsImFzc2lnbkFuYWx5c3QiOiIifQ%3D%3D; expires=Fri, 27-Oct-2017 18:06:36 GMT; Max-Age=60; domain=localhost"
},
{
"name": "Cache-Control",
"value": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
},
{
"name": "Content-Security-Policy",
"value": "default-src 'self' *.sw.test; frame-src *.twitter.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.twitter.com *.twimg.com; style-src 'self' 'unsafe-inline' *.twitter.com *.twimg.com; img-src 'self' data: *.twimg.com *.twitter.com;"
},
{
"name": "Connection",
"value": "Keep-Alive"
},
{
"name": "Keep-Alive",
"value": "timeout=5, max=100"
},
{
"name": "Content-Length",
"value": "0"
},
{
"name": "Expires",
"value": "Thu, 19 Nov 1981 08:52:00 GMT"
}
],
"cookies": [
{
"name": "SimpleSAML",
"value": "62d6b2ebea7f66b0360a328dcb4f77a7",
"path": "/",
"expires": null,
"httpOnly": true,
"secure": false
},
{
"name": "PHPSESSID",
"value": "k9hpb09i3omt43bv7gireeuid0",
"path": "/",
"expires": null,
"httpOnly": true,
"secure": false
},
{
"name": "auth",
"value": "eyJzdWNjZXNzIjoiQXV0aGVudGljYXRpb24gc3VjY2VzcyEiLCJjdXN0aWQiOiJhbGFuYyIsInNlc3Npb25JZCI6IjU5ZjM3NTcwLTBhZTJmNzAzLTNmMTIiLCJ3ZWJGbGFncyI6IjIxNDc0ODk1NTEiLCJjYWxsQ2xhc3MiOiJJbmNpZGVudCIsImFzc2lnbkdyb3VwIjoiU1VQUE9SVCIsImFzc2lnbkFuYWx5c3QiOiIifQ%3D%3D",
"domain": "localhost",
"expires": "2017-10-27T18:06:36.254Z",
"httpOnly": false,
"secure": false
}
],
"content": {
"size": 0,
"mimeType": "text/html",
"compression": 0
},
"redirectURL": "http://localhost/sw/selfservice",
"headersSize": 1104,
"bodySize": 0,
"_transferSize": 1104
},
Make sure your $cred var is defined and a valid string
Make sure the result of the parse_url() function on $location returns a valid string....it has to match exactly the domain you work on so watch out for subdomain issues.
Obviously make sure you check before it expires....60 seconds.
I have a feed from a parcel tracking service that i am trying to integrate into my site. I have a url which allows me to put the tracking number at the end and get a json response. I have multiple objects from this which include some static info such as the senders address and some info which I will need to use a foreach for like the tracking progress.
I believe I have got the string okay however I am not sure how I am meant to display the info.
This is what I have so far:
Example URL:
domain.com/REST_Service/webservice/consignee/SelfshipService.svc/web/Tracking/84941354665
URL Returns:
{
"Agent": null,
"Consignee": {
"Address1": "25 HEATHFIELD ROAD",
"Address2": "SHOLING",
"Address3": "",
"Code": null,
"Company": "ERIK HANSON",
"Country": "GREAT BRITAIN",
"Dept": "",
"Email": "ERIK.HANSON66#GOOGLEMAIL.COM",
"Name": "",
"Phone": "07770320490",
"Postcode": "SO19 1DL",
"State": "HANTS",
"Town": "SOUTHAMPTON"
},
"CrossIdx": "",
"Error": null,
"NonDel": null,
"POD": {
"Date": "13 Jul 2016",
"Status": "Harnett",
"Time": "09:17"
},
"Pieces": 1,
"PosErr": 0,
"Tracks": [
{
"Date": "13 Jul 2016",
"Status": "Out for delivery",
"Time": "07:10"
},
{
"Date": "13 Jul 2016",
"Status": "At Delivery location Portsmouth",
"Time": "02:24"
},
{
"Date": "13 Jul 2016",
"Status": "At Delivery location Portsmouth",
"Time": "02:22"
},
{
"Date": "12 Jul 2016",
"Status": "Arrived At Ryton",
"Time": "22:12"
},
{
"Date": "12 Jul 2016",
"Status": "Preparing for despatch",
"Time": "14:00"
},
{
"Date": "12 Jul 2016",
"Status": "Scanned into OCS HEATHROW LONDON",
"Time": "13:59"
},
{
"Date": "12 Jul 2016",
"Status": "Consignment details verified",
"Time": "13:59"
},
{
"Date": "14 Jun 2016",
"Status": "Shipment prepared by customer",
"Time": "11:20"
},
{
"Date": "02 Jan 2003",
"Status": "Collected from Customer",
"Time": "09:32"
}
],
"Weight": 7
}
Current PHP:
//set tracking url
$url = "http://www.ocscourier.co.uk/REST_Service/webservice/consignee/SelfshipService.svc/web/Tracking/84941354665";
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "http://www.ocscourier.co.uk/REST_Service/webservice/consignee/SelfshipService.svc/web/Tracking/84941354665");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
//call api
//$json = file_get_contents($url);
$json = json_decode($output);
$Address1 = $json->results[0]->Consignee->Address1;
$Address2 = $json->results[0]->Consignee->Address2;
echo "Address 1: " . $Address1 . ", Address 2: " . $Address2;
Your json string doesn't have any results key (so I'm not sure why you trying to access results[0].
You can just use
$Address1 = $json->Consignee->Address1;
$Address2 = $json->Consignee->Address2;
Check this code:
$s = <<< END
{
"Agent": null,
"Consignee": {
"Address1": "25 HEATHFIELD ROAD",
"Address2": "SHOLING",
"Address3": "",
"Code": null,
"Company": "ERIK HANSON",
"Country": "GREAT BRITAIN",
"Dept": "",
"Email": "ERIK.HANSON66#GOOGLEMAIL.COM",
"Name": "",
"Phone": "07770320490",
"Postcode": "SO19 1DL",
"State": "HANTS",
"Town": "SOUTHAMPTON"
},
"CrossIdx": "",
"Error": null,
"NonDel": null,
"POD": {
"Date": "13 Jul 2016",
"Status": "Harnett",
"Time": "09:17"
},
"Pieces": 1,
"PosErr": 0,
"Tracks": [
{
"Date": "13 Jul 2016",
"Status": "Out for delivery",
"Time": "07:10"
},
{
"Date": "13 Jul 2016",
"Status": "At Delivery location Portsmouth",
"Time": "02:24"
},
{
"Date": "13 Jul 2016",
"Status": "At Delivery location Portsmouth",
"Time": "02:22"
},
{
"Date": "12 Jul 2016",
"Status": "Arrived At Ryton",
"Time": "22:12"
},
{
"Date": "12 Jul 2016",
"Status": "Preparing for despatch",
"Time": "14:00"
},
{
"Date": "12 Jul 2016",
"Status": "Scanned into OCS HEATHROW LONDON",
"Time": "13:59"
},
{
"Date": "12 Jul 2016",
"Status": "Consignment details verified",
"Time": "13:59"
},
{
"Date": "14 Jun 2016",
"Status": "Shipment prepared by customer",
"Time": "11:20"
},
{
"Date": "02 Jan 2003",
"Status": "Collected from Customer",
"Time": "09:32"
}
],
"Weight": 7
}
END;
$json = json_decode($s);
$Address1 = $json->Consignee->Address1;
$Address2 = $json->Consignee->Address2;
echo "Address 1: " . $Address1 . ", Address 2: " . $Address2;
Here is the output:
Address 1: 25 HEATHFIELD ROAD, Address 2: SHOLING
Below is json string in $json variable and access with RecursiveIteratorIterator
Example
$json='{
"Agent": null,
"Consignee": {
"Address1": "25 HEATHFIELD ROAD",
"Address2": "SHOLING",
"Address3": "",
"Code": null,
"Company": "ERIK HANSON",
"Country": "GREAT BRITAIN",
"Dept": "",
"Email": "ERIK.HANSON66#GOOGLEMAIL.COM",
"Name": "",
"Phone": "07770320490",
"Postcode": "SO19 1DL",
"State": "HANTS",
"Town": "SOUTHAMPTON"
},
"CrossIdx": "",
"Error": null,
"NonDel": null,
"POD": {
"Date": "13 Jul 2016",
"Status": "Harnett",
"Time": "09:17"
},
"Pieces": 1,
"PosErr": 0,
"Tracks": [
{
"Date": "13 Jul 2016",
"Status": "Out for delivery",
"Time": "07:10"
},
{
"Date": "13 Jul 2016",
"Status": "At Delivery location Portsmouth",
"Time": "02:24"
},
{
"Date": "13 Jul 2016",
"Status": "At Delivery location Portsmouth",
"Time": "02:22"
},
{
"Date": "12 Jul 2016",
"Status": "Arrived At Ryton",
"Time": "22:12"
},
{
"Date": "12 Jul 2016",
"Status": "Preparing for despatch",
"Time": "14:00"
},
{
"Date": "12 Jul 2016",
"Status": "Scanned into OCS HEATHROW LONDON",
"Time": "13:59"
},
{
"Date": "12 Jul 2016",
"Status": "Consignment details verified",
"Time": "13:59"
},
{
"Date": "14 Jun 2016",
"Status": "Shipment prepared by customer",
"Time": "11:20"
},
{
"Date": "02 Jan 2003",
"Status": "Collected from Customer",
"Time": "09:32"
}
],
"Weight": 7
}';
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
echo "$key:\n</br>";
} else {
echo "$key => $val\n";
}
}
OUTPUT:
Agent => Consignee:
Address1 => 25 HEATHFIELD ROAD Address2 => SHOLING Address3 => Code => Company => ERIK HANSON Country => GREAT BRITAIN Dept => Email => ERIK.HANSON66#GOOGLEMAIL.COM Name => Phone => 07770320490 Postcode => SO19 1DL State => HANTS Town => SOUTHAMPTON CrossIdx => Error => NonDel => POD:
Date => 13 Jul 2016 Status => Harnett Time => 09:17 Pieces => 1 PosErr => 0 Tracks:
0:
Date => 13 Jul 2016 Status => Out for delivery Time => 07:10 1:
Date => 13 Jul 2016 Status => At Delivery location Portsmouth Time => 02:24 2:
Date => 13 Jul 2016 Status => At Delivery location Portsmouth Time => 02:22 3:
Date => 12 Jul 2016 Status => Arrived At Ryton Time => 22:12 4:
Date => 12 Jul 2016 Status => Preparing for despatch Time => 14:00 5:
Date => 12 Jul 2016 Status => Scanned into OCS HEATHROW LONDON Time => 13:59 6:
Date => 12 Jul 2016 Status => Consignment details verified Time => 13:59 7:
Date => 14 Jun 2016 Status => Shipment prepared by customer Time => 11:20 8:
Date => 02 Jan 2003 Status => Collected from Customer Time => 09:32 Weight => 7
I did a little PHP script that uses this principle: https://developers.facebook.com/docs/facebook-login/access-tokens/expiration-and-extension#long-via-code
Unfortunately when I send the CODE to the user and try to HTTPrequest (javascript), the page that should give me the MACHINE_ID responds with a random, changing string.
I guess HTTPrequest is called basically from the server, not the client. When I use direct URL connection I get the same string every time, but I cannot use the data, because it is just a web page, not a response.
Shouldn't the MACHINE_ID always be the same (for a certain device/browser session)?
{
"session_key": "5.xLL8XelWvN17yQ.1530200602.46-100004938759387",
"uid": 100004938759387,
"secret": "62818f28dadf1e5fdea17c70cc42b4e5",
"access_token": "EAAAAUaZA8jlABAF8vs7Xp3bYhFrUjGZC7IJVIkBtsxGEbwjIhy7PtysyYCZB4ZBZAlXNvxSbsYZA9giZC8ZBhWZCpaTuYxGZBhGSo0sb1r5R8XPjmxbSHZCjuQgxjcgPlbVwsAVdboRHEyyc9cN6FfPFz3Jv9cB8xguVk4gyRCD6JQ5fhHBXxdykQwl",
"machine_id": "GgI1W1EjtchM9UoB1IiILZke",
"session_cookies": [{
"name": "c_user",
"value": "100004938759387",
"expires": "Fri, 28 Jun 2019 15:43:22 GMT",
"expires_timestamp": 1561736602,
"domain": ".facebook.com",
"path": "\/",
"secure": true
}, {
"name": "xs",
"value": "46:xLL8XelWvN17yQ:2:1530200602:15323:8134",
"expires": "Fri, 28 Jun 2019 15:43:22 GMT",
"expires_timestamp": 1561736602,
"domain": ".facebook.com",
"path": "\/",
"secure": true,
"httponly": true
}, {
"name": "fr",
"value": "0LpS1kk8BIpMZ6ZnX.AWUXzwpmVcljO_CD31ozKSBgHno.BYGKXA.3G.AAA.0.0.BbNQIa.AWUgcG86",
"expires": "Fri, 28 Jun 2019 15:43:22 GMT",
"expires_timestamp": 1561736602,
"domain": ".facebook.com",
"path": "\/",
"secure": true,
"httponly": true
}, {
"name": "datr",
"value": "GgI1W1EjtchM9UoB1IiILZke",
"expires": "Sat, 27 Jun 2020 15:43:22 GMT",
"expires_timestamp": 1593272602,
"domain": ".facebook.com",
"path": "\/",
"secure": true,
"httponly": true
}],
"confirmed": true,
"identifier": "Christian.palele",
"user_storage_key": "7086edcf13fb66e64be979ea719e8cd24d658ed3bce735e4f871dc69eda26409"
}
{
"response": {
"request": {
"date": "Tue, 13 Sep 2011 11:24:28 +0200",
"resource": "/users/2cec711d-ca14-4472-98c8-ca74432bc2d3.json",
"status": {
"flag": "success",
"code": 200
}
},
"result": {
"data": {
"user": {
"user_token": "2cec711d-ca14-4472-98c8-ca74432bc2d3",
"date_creation": "Tue, 1 Sep 2011 11:01:12 +0200",
"date_last_login": "Tue, 13 Sep 2011 01:05:07 +0200",
"num_logins": "64",
"identities": [{
"identity_token": "cd3bd13b-b393-4d6c-a7f6-950b4c47938f",
"provider": "twitter",
"id": "http://twitter.com/ExampleUser",
"displayName": "Firstname Lastname",
"name": {
"formatted": "Firstname Lastname"
},
"gender": "male",
"utcOffset": "2:00"
}, {
"identity_token": "3ab5257b-ba2b-4242-a7f6-950b4c47938f",
"provider": "facebook",
"id": "http://www.facebook.com/profile.php?id=1046121518",
"displayName": "Firstname Lastname",
"name": {
"formatted": "Firstname Lastname",
"givenName": "Firstname",
"familyName": "Lastname"
},
"gender": "male",
"birthday": "01/01/1980",
"utcOffset": "2:00",
"emails": [{
"value": "email#example.com",
"is_verified": "true"
}]
}]
}
}
}
}
}
The above code is Result: the code returned by the ONEALL API
I am using oneall api for my website social login ,after i login i requested user details by get method using user token, the values like last login got by using $data->user->date_last_login, but i am unable to get email and dispalyname how can i do that one , i didn't wrote all the code i gave just sample, hope this will help for others also
http://docs.oneall.com/api/resources/users/read-user-details/
If you follow the object structure, you can get them as:
$data = json_decode($json);
$displayName = $data->response->result->data->user->identities[1]->displayName;
$email = $data->response->result->data->user->identities[1]->emails[0]->value;
Update:
If you are using intermediate var for response data, then just shrink the chain:
$json = json_decode($result_json);
//extract response data
$data = $json->response->result->data;
$displayName = $data->user->identities[1]->displayName;
$email = $data->user->identities[1]->emails[0]->value;
This will give you:
Firstname Lastname
email#example.com
Here we go complete code, based on your JSON object:
<?php
$result_json = '
{
"response": {
"request": {
"date": "Tue, 13 Sep 2011 11:24:28 +0200",
"resource": "/users/2cec711d-ca14-4472-98c8-ca74432bc2d3.json",
"status": {
"flag": "success",
"code": 200
}
},
"result": {
"data": {
"user": {
"user_token": "2cec711d-ca14-4472-98c8-ca74432bc2d3",
"date_creation": "Tue, 1 Sep 2011 11:01:12 +0200",
"date_last_login": "Tue, 13 Sep 2011 01:05:07 +0200",
"num_logins": "64",
"identities": [{
"identity_token": "cd3bd13b-b393-4d6c-a7f6-950b4c47938f",
"provider": "twitter",
"id": "http://twitter.com/ExampleUser",
"displayName": "Firstname Lastname",
"name": {
"formatted": "Firstname Lastname"
},
"gender": "male",
"utcOffset": "2:00"
}, {
"identity_token": "3ab5257b-ba2b-4242-a7f6-950b4c47938f",
"provider": "facebook",
"id": "http://www.facebook.com/profile.php?id=1046121518",
"displayName": "Firstname Lastname",
"name": {
"formatted": "Firstname Lastname",
"givenName": "Firstname",
"familyName": "Lastname"
},
"gender": "male",
"birthday": "01/01/1980",
"utcOffset": "2:00",
"emails": [{
"value": "email#example.com",
"is_verified": "true"
}]
}]
}
}
}
}
}';
$json = json_decode($result_json);
$data = $json->response->result->data;
echo $displayName = $data->user->identities[1]->displayName;
echo '<br>';
echo $email = $data->user->identities[1]->emails[0]->value;
?>
I need some help with the movie db api. I constantly get a connection timed out error. Below is my code, I'm trying to just output the raw json respone so I can work my way from there.
$header_opt = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept: application/json\r\n" .
"Content-Type: application/json\r\n"
)
);
$headers = stream_context_create($header_opt);
$rawjson = file_get_contents('http://api.themoviedb.org/3/movie/tt0076759?api_key=myapikey', false, $headers);
$cleansjon = json_decode($rawjson);
echo $cleansjon;
And this is the error I get.
Warning: filegetcontents(http://api.themoviedb.org/3/movie/tt0076759?api_key=myapikey) [function.file-get-contents]: failed to open stream: Connection timed out in /*///*/public_html/index.php on line 11
I hope that someone can help me with this.
Edit: Added HAR response
{
"log": {
"version": "1.2",
"creator": {
"name": "WebInspector",
"version": "537.20"
},
"pages": [
{
"startedDateTime": "2013-01-27T09:51:02.534Z",
"id": "page_1",
"title": "http://*MyWebsite*/tmdb.php",
"pageTimings": {
"onContentLoad": 60636,
"onLoad": 60635
}
}
],
"entries": [
{
"startedDateTime": "2013-01-27T09:51:02.534Z",
"time": 60197,
"request": {
"method": "GET",
"url": "http://*MyWebsite*/tmdb.php",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "DNT",
"value": "1"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,sdch"
},
{
"name": "Host",
"value": "*MyHost*"
},
{
"name": "Accept-Language",
"value": "nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.20 (KHTML, like Gecko) Chrome/25.0.1328.0 Safari/537.20"
},
{
"name": "Accept",
"value": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
},
{
"name": "Cache-Control",
"value": "max-age=0"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "Accept-Charset",
"value": "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
}
],
"queryString": [],
"cookies": [],
"headersSize": 443,
"bodySize": 0
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Date",
"value": "Sun, 27 Jan 2013 09:51:02 GMT"
},
{
"name": "Content-Encoding",
"value": "gzip"
},
{
"name": "Server",
"value": "Apache/2"
},
{
"name": "Vary",
"value": "Accept-Encoding,User-Agent"
},
{
"name": "Content-Type",
"value": "text/html"
},
{
"name": "Connection",
"value": "Keep-Alive"
},
{
"name": "Keep-Alive",
"value": "timeout=1, max=100"
},
{
"name": "Content-Length",
"value": "260"
}
],
"cookies": [],
"content": {
"size": 342,
"mimeType": "text/html",
"compression": 82
},
"redirectURL": "",
"headersSize": 234,
"bodySize": 260
},
"cache": {},
"timings": {
"blocked": 0,
"dns": 13,
"connect": 29,
"send": 0,
"wait": 60147,
"receive": 5,
"ssl": -1
},
"pageref": "page_1"
}
]
}
}
You can remove the Content-Type header, this would be required if you submit JSON using HTTP PUT or POST.
The error indicates, that file_get_contents does not get a response from the host api.themoviedb.org
I constantly get a connection timed out error.
Does constantly mean always or often?
If you see this frequently either your Internet uplink or the movie db server has a problem.
Maybe there is no problem at all. Your application is trying to connect to a server and gets a timeout error.