I'm trying to use Tumblrs API and when I visit the URL for the API I get this below
{
"meta": {
"status": 200
"msg": "OK",
},
"response": {
"blog": {
"title": "Ex-Sample",
"posts": 20,
"name": "example",
"url": "http://example.tumblr.com/",
"updated": 1327794725,
"description": "A sample document used to provide examples of the various [and <i>varying</i>] HTML tags Tumblr puts out. Quote, specifically, has a lot of variants.",
"ask": false
}
}
}
The URL is http://api.tumblr.com/v2/blog/example.tumblr.com/info?api_key=(APIKEY)
I'm trying to get what the "post" number is with that URL above. How would I do that in PHP and echo the number only out?.
That looks like a JSON string, so...
$msg = '{"meta" etc.....';
$data = json_decode($msg);
echo $data['meta']['response']['blog']['posts'];
You can use
var_dump($data);
to dump the entire response in a nicely formatted tree structure.
Related
I'm posting data to my API endpoint. it's simple JSON data. But I'm getting error 404 when posting data as raw JSON but if I post the same data at the same endpoint as raw text its works.
working as raw text
getting error 404 as raw JSON
<?php
var_dump(http_response_code());
echo "hello";
var_dump($_POST);
echo file_get_contents("php://input");
I have removed all code from the API end point and just trying to print post data.
Sample JSON :
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "456",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "123456789",
"phone_number_id": 123456789
},
"contacts": [
{
"profile": {
"name": "NAME"
},
"wa_id": 123456789
}
],
"messages": [
{
"from": 123456789,
"id": "wamid.ID",
"timestamp": 123456789,
"text": {
"body": "MESSAGE_BODY"
},
"type": "text"
}
]
},
"field": "messages"
}
]
}
]
}
I have checked JSON and it's a valid JSON. no special character but still unable to solve this issue.
One more thing its working on my local machine under XAMPP but not on Linux shared server.
I am trying send email through Microsoft graph api. I created a message object like the following.
{"message":{"subject":"hellowolrd","body":{"contentType":"text","content":"wow"}},"toRecipients":{"emailAddress":{"address":"example#yahoo.com"}}}
But gets 400 error with invalid recipient. Can anybody help me why I am getting this error.
It seems you have a syntax issue in your JSON request.Look closely after content you have an extra closing } which means you are not posting 'toRecipients' in the message.
{"message":{"subject":"hellowolrd","body":{"contentType":"text","content":"wow"}},"toRecipients":{"emailAddress":{"address":"example#yahoo.com"}}}
Instead try below JSON to make it work -
{
"message": {
"subject": "hellowolrd",
"body": {
"contentType": "text",
"content": "wow"
},
"toRecipients": [
{
"emailAddress": {
"address": "example#yahoo.com"
}
}
]
}
}
Thanks!
The invalid recipient was caused by a different json structure. I had to exactly match the following structure that was provided in one of their example.
$mailArgs ='
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "Lunch Invited"
},
"toRecipients": [
{
"emailAddress": {
"address": "example#example.com"
}
}
]
}
}';
So I created a JSON array to match exactly the same structure and it worked!
I'm using zoho crm..
I get the json data below returned from a query
however I'm struggling to get the value of a string inside the returned data
Here is a sample of the data returned
"response": {
"result": {
"Deals": {
"row": {
"no": "1",
"FL": [
{
"val": "DEALID",
"content": "3508588000000206039"
},
{
"val": "SMOWNERID",
"content": "3508588000000176021"
},
{
"val": "Amount",
"content": "5000"
}
I'm trying to get the Amount value
Here is the PHP code
$json = file_get_contents($url);
$obj = json_decode($json);
$amount = $obj->result->Deals->row->FL['Amount'];
echo 'Deal Amount : £'.$amount;
Thanks In Advance
You need to change a bit
$amount = $obj->response->result->Deals->row->FL[2]->content;
//--------------^index------------------------^index---^column name need to be correct---
Dealing with Zoho response could get messy. You could use this library to help smoothen things for you.
In the meantime, $obj->response->result->Deals->row->FL[2]->content; should do the trick for you.
I'm trying to get data from the following JSON file using PHP
I Want To Get All URls (link) ,
http://www.google.com
http://www.bing.com
Json
Here is what I tried
PHP
Thanks
You cannot access an object property using a number, it must be a string.
It is much easier to output json_decode as an array, and access properties that way. To do this, put true as the second parameter.
<?php
$json = '
{
"news": {
"name": "yahoo",
"url": "https://yahoo.com"
},
"links": [
{
"id": "1",
"url": "https://google.com"
},
{
"id": "2",
"url": "https://bing.com"
}
]
}';
$decode = json_decode($json, true);
echo $decode['links'][0]['url'];
I have a JSON that looks like this, and I used json_decode(file_get_contents('php://input'),true); to turn it into an array
{
"object": "page",
"entry": [
{
"id": "",
"time":,
"messaging": [
{
"sender": {
"id": ""
},
"recipient": {
"id": ""
},
"timestamp":,
"message": {
"mid": "",
"seq": "",
"text": "STORE, POSTAL CODE"
}
}
]
}
]
}
After the JSON was decoded I wanted to grab the text portion of the JSON, so i did
$message = ($post['entry'][0]['messaging'][0]['message']['text']
$query = explode(',', $message);
I then used $query[0], and $query[1] in some SQL queries.
For some reason, when I hardcode $message to some text like $message = 'store, postal'; it'll work but not when I use explode.
FYI, this json is coming from Facebook as I'm using the messenger api.
Check that $post['entry'][0]['messaging'][0]['message']['text']
gives you "STORE, POSTAL CODE".
As I see json contains uppercase strings and your example is lowercase. Maybe this is important in your code further.