I'm using the Bit2Check.com API. I want to check emails registered on PayPal. But after supplying email address to the API, I get this response:
{"Paypal":"Linked"}
I just want to grab the "Linked" part.
You are providing me with no code, so I will have to try to answer your question in general.
You probably have
{"Paypal" : "Linked"}
stored within some variable. To access the "Linked" part, you need to json_decode() it. Code retrieving just the "Linked" string would like something like this.
$yourVariable = '{"Paypal" : "Linked"}';
$decoded = json_decode($yourVariable);
// Access only linked part
$onlyLinked = $decoded->Paypal;
// Or maybe you are interested in boolean value?
$isLinked = ($decoded->Paypal == "Linked") ? true : false;
To read more about json_decode(), visit this article on php.net.
Related
I'm trying to use this api (currency exchange api). This returns something like this:
{
"from":"USD",
"to":"HKD",
"rate":7.7950999999999996958877090946771204471588134765625
}
I send the request with file_get_contents() and this seems to work.
My problem is that I can't access the array key rate.
$r = file_get_contents('https://cc.hirak.cc/usd_hkd');
print_r($r['rate']); // nothing is shown. This is the problem.
print_r($r); // result shows ( all the array )
How can I access just the rate key?
you are accessing an string instead of array,
Try this code, I think this will work:
$r = json_encode(file_get_contents('https://cc.hirak.cc/usd_hkd'),true);
I have an observer event that is capturing customer details anytime they are updated. At this point it posts that information to a var log.
I would like to get it to post to a SOAP API url.
SOAP API URL
at this point I am trying to be pointed in the right direction of how to do this, I believe I need to write the information into an XML that matches the API.
I only have 6 fields that need to be filled so I don't think it will be to hard.
$fon = $billingaddress->getTelephone();
$street1 = $billingaddress->getStreet(1);
$street2 = $billingaddress->getStreet(2);
$city = $billingaddress->getCity();
$region = $billingaddress->getRegion();
$postcode = $billingaddress->getPostcode();
The phone number doubles as the customer #
Can somebody help me with the code to write the XML?
This chunk will go inside your body tag, as shown in the examples HERE. For the XML, it is pretty straightforward, and you can do it as one $request variable instead of assigning several:
<?php
$request = '<UpdateCustomer xmlns="http://www.dpro.com/DPAPIServices">'.
'<aRequest>'.
// '<Username>'..'</Username>'.
// '<Password>'..'</Password>'.
'<CustomerNumber>'.$billingaddress->getTelephone();.'</CustomerNumber>'.
'<CustomerName>'.$billingAddress->getFirstname().' '.$billingAddress->getLastname().'</CustomerName>'.
'<CustomerAddress1>'.$billingaddress->getStreet(1).'</CustomerAddress1>'.
'<CustomerAddress2>'.$billingaddress->getStreet(2).'</CustomerAddress2>'.
'<CustomerCity>'.$billingaddress->getCity().'</CustomerCity>'.
'<CustomerState>'.$billingaddress->getRegion().'</CustomerState>'.
'<CustomerZip>'.$billingaddress->getPostcode().'</CustomerZip>'.
'</aRequest>'.
'</UpdateCustomer>';
?>
NOTE:
I commented out the Username and Password because they weren't included in your example, and I am unsure whether they are your API user's credentials or related to the Customer.
You shouldn't need to write any XML when working with a SOAP API that already exists. Use the built-in SoapClient.
Have a look at the answers to this question if you need help with that: How to make a PHP SOAP call using the SoapClient class
I'm using PHP to build an application that gets some statistics from individual Instagram accounts.
I do a get request to the following URL to get a JSON formatted string:
https://www.instagram.com/{username}/?__a=1
With json_decode, I get the followers and the followings by:
$follows = $data['user']['follows']['count'];
$followedBy = $data['user']['followed_by']['count'];
But I don't know how to get the posts count.
For example for NASA profile:
https://www.instagram.com/nasa/
... I need the number (currently) 1.967.
Any idea?
And a final question: do I have to use API Key to get the stats, or the GET to the above URL is enough?
what is wrong with
$json = file_get_contents('https://www.instagram.com/nasa/?__a=1');
$obj = json_decode($json);
echo $obj->user->media->count;
it just spit out the correct post count as you wanted?
As of now (2020) Instagram has made some changes to the JSON response and the code below does the same as the accepted answer above, also with formatted output.
$ig = json_decode(file_get_contents('https://www.instagram.com/nasa/?__a=1'));
echo number_format($ig->graphql->user->edge_owner_to_timeline_media->count);
I am trying to check if a contact exist already before creating it.
below is a sample of my code,
$contact_fields_index = array("name"=>"Paul Pierre", "mail"=>"paul#barnardmail.net");
$existingContacts = PodioContact::get_for_app( $PODIO_APPID , $contact_fields_index);
$existingContacts is always empty, even though the contact exists in the workspace.
What am I doing wrong ?
I suspect your mail might be not matching, or your name.
Did you try without the attributes parameter? For example:
$existingContacts = PodioContact::get_for_app( $PODIO_APPID );
That should bring back all contacts and when output the $existingContacts array you can see if the one you are looking for is in there.
I'm trying to get a user's site_id from posterous. This data seems to be nowhere in the user's profile, and nothing in the FAQ or help or docs indicates how to find this.
The only method I can find is to request a list of sites over API,
So, that's what I'm trying to do, and I get back a json response, and, indeed, the site_id of any site the user has on posterous is in there, and I just want to output this.
First I tried with (where $result is the json response)
$siteid = preg_match('"site_id": \d+', $result);
echo $siteid;
I get nothing.
Then I tried with
json_decode($result);
echo $result->site_id;
I still get nothing.
I can see, in the json response ($result),
"site_id": $somenumber;
Why can't I extract this data with either preg_match or json_decode? Is there another, better method?
My full code is pasted at http://tonybaldwin.me/paste/index.php?3u
The Posterous list-of-sites API returns a list (as you might expect) of mappings. Thus, what you need to do is first pick the right item of the list, and then read it's id key.
$result = json_decode($response);
$first_result = $result[0];
$first_result_id = $first_result["id"];
echo $first_result_id;