Hi I am using contextIO api for fetch emails.I got a code from GitHub ,but it shows some errors.I am using this code ,
include_once("class.contextio.php");
// see https://console.context.io/#settings to get your consumer key and consumer secret.
$contextIO = new ContextIO('asssasas','sdsd1111sdsdsd');
$accountId = null;
// list your accounts
$r = $contextIO->listAccounts();//print_r($r);
foreach ($r->getData() as $account) {
echo $account['id'] . "\t" . join(", ", $account['email_addresses']) . "\n";
if (is_null($accountId)) {
$accountId = $account['id'];
}
}
But it shows a n error
Fatal error: Call to a member function getData() on a non-object
Is it need a seperate gmail authentication? anyone please help me
All of the functions in the ContextIO library return a ContextIOResponse object, or false if the API returns an http error code. Check for if($r !== false) before you call getData() on $r and you should be good to go!
(Note: I work on the context.io team and am currently the primary developer on the PHP libraries.)
Related
I have been working around Bit-Wasp/bitcoin-php library for a while now and I encountered problems with it that I cannot resolve.
I have this as my code:
public function bitcoinWalletFromPublicKey($key, $index) {
$adapter = Bitcoin::getEcAdapter();
if (config('market.btc_network') == "mainnet") {
$btc = NetworkFactory::bitcoin();
$bitcoinPrefixes = new BitcoinRegistry();
} else {
$btc = NetworkFactory::bitcoinTestnet();
$bitcoinPrefixes = new BitcoinTestnetRegistry();
}
$slip132 = new Slip132(new KeyToScriptHelper($adapter));
$pubkeytype=substr($key, 0, 4);
if ($pubkeytype=='xpub' || $pubkeytype =='tpub') $pubPrefix = $slip132->p2pkh($bitcoinPrefixes);
if ($pubkeytype=='ypub') $pubPrefix = $slip132->p2shP2wpkh($bitcoinPrefixes);
if ($pubkeytype=='zpub' || $pubkeytype =='vpub') $pubPrefix = $slip132->p2wpkh($bitcoinPrefixes);
$config = new GlobalPrefixConfig([
new NetworkConfig($btc, [$pubPrefix])
]);
$serializer = new Base58ExtendedKeySerializer(
new ExtendedKeySerializer($adapter, $config)
);
$path = '0/' . $index;
$fkey = $serializer->parse($btc, $key);
$child_key = $fkey->derivePath($path);
#$account0Key = $child_key->derivePath("84'/0'/0'");
#$child_key = $fkey->derivePath("0/1");
//dd($child_key->getAddress(new AddressCreator())->getAddress());
return $child_key->getAddress(new AddressCreator())->getAddress();
}
I have two problems with this code:
Problem #1
On the first few lines of the code you will see that I used an If statement to check what network should it use. On my test im using testnet network and I'm sure as well that the code on my If / else { # code } works and it uses NetworkFactory::bitcoinTestnet() and new BitcoinTestnetRegistry() properly;
$key variable represents the Master Public Key of my user from Electrum wallet or whatever with a format of (xpub#########################/vpub#########################) or in my case since its on testnet it uses tpub######################### format. However, it returns an address with a format of bc#########, this means that its passing on mainnet network wherein it should be on testnet network.
Problem #2
On lower part of my code, I'm using $fkey = $serializer->parse($btc, $key); and $child_key = $fkey->derivePath($path) wherein $path = '0/' $index. $index here are just random numbers. It can be 0/1 or 0/99 or whatever 0/random.
Problem here is that somehow related to Problem #1, after it generates the wrong address, when I try to use this address for transaction my rpc returns an invalid address Error. As you can see as well I have a commented code $account0Key = $child_key->derivePath("84'/0'/0'"); wherein i got an error that it needs a private key instead of a public one. Now, my concern is that I do not want the users of the system i'm making to put their private keys whatsoever as it will might just compromise their wallets.
Basically, What I want to achieve using with this library from BitWasp is when a user put in their master public key from their wallet, my system would be able to then generate an address to be used for a btc transaction. Please help.
Passing the network inside the getAddress() method works
return $child_key->getAddress(new AddressCreator())->getAddress($btc);
I'm hoping to get a little assistance with something that is probably pretty basic -- I'm attempting to deploy the Square Checkout API with my website. I've been able to successfully install the SDK, and I've used it to successfully pull my sandbox location ID, to test it's function.
I've proceeded to build a page employing only the demo script on the Checkout API page, as seen below:
<?php
#Set the required includes globally
require_once '../config.php';
require INC_PATH . '/squareup/autoload.php';
/*
** Script for submitting payment information
** Utilizing Square API documentation at:
** https://docs.connect.squareup.com/payments/checkout/setup
*/
//Replace your access token and location ID
$accessToken = '<MY SANDBOX KEY>'; // Sandbox
$locationId = '<MY SANDBOX LOCATION ID>'; // Sandbox
// Create and configure a new API client object
$defaultApiConfig = new \SquareConnect\Configuration();
$defaultApiConfig->setAccessToken($accessToken);
$defaultApiClient = new \SquareConnect\ApiClient($defaultApiConfig);
$checkoutClient = new SquareConnect\Api\CheckoutApi($defaultApiClient);
//Create a Money object to represent the price of the line item.
$price = new \SquareConnect\Model\Money;
$price->setAmount(600);
$price->setCurrency('USD');
//Create the line item and set details
$book = new \SquareConnect\Model\CreateOrderRequestLineItem;
$book->setName('The Shining');
$book->setQuantity('2');
$book->setBasePriceMoney($price);
//Puts our line item object in an array called lineItems.
$lineItems = array();
array_push($lineItems, $book);
// Create an Order object using line items from above
$order = new \SquareConnect\Model\CreateOrderRequest();
$order->setIdempotencyKey(uniqid()); //uniqid() generates a random string.
//sets the lineItems array in the order object
$order->setLineItems($lineItems);
## STEP 2: Create a checkout object
$checkout = new \SquareConnect\Model\CreateCheckoutRequest();
$checkout->setIdempotencyKey(uniqid()); //uniqid() generates a random string.
$checkout->setOrder($order); //this is the order we created in the previous step
try {
$result = $checkoutClient->createCheckout(
$locationId,
$checkout
);
//Save the checkout ID for verifying transactions
$checkoutId = $result->getId();
//Get the checkout URL that opens the checkout page.
$checkoutUrl = $result->getCheckoutPageUrl();
print_r('Complete your transaction: ' + $checkoutUrl);
}
catch (Exception $e) {
echo 'Exception when calling CheckoutApi->createCheckout: ', $e->getMessage(), PHP_EOL;
}
I get a 500 error from my webserver when attempting to run this script through my browser, in my httpd error_log I get the following error message:
PHP Fatal error: Uncaught Error: Call to undefined method SquareConnect\\Model\\CreateCheckoutResponse::getId() in <LOCATION>:62\nStack trace:\n#0 {main}\n thrown in <LOCATION> on line 62
Any thoughts on why the getId() method is undefined? Thanks.
UPDATE
I commented out the function calls after the createCheckout() portion of the try{} block, and then ran a var_dump() on $result to make sure I was in fact getting some sort of response. I am getting back the expected result! So I KNOW the API/SDK is working now, I just can't figure out why the $result object is unable to accept the follow-up functions.
Revised try block:
try {
$result = $checkoutClient->createCheckout(
$locationId,
$checkout
);
/*
//Save the checkout ID for verifying transactions
$checkoutId = $result->getId();
//Get the checkout URL that opens the checkout page.
$checkoutUrl = $result->getCheckoutPageUrl();
print_r('Complete your transaction: ' + $checkoutUrl);
*/
}
catch (\Exception $e) {
echo 'Exception when calling CheckoutApi->createCheckout: ', $e->getMessage(), PHP_EOL;
}
var_dump($result); //test to see if any non-zero response to createCheckout() function.
Any thoughts based on this revision? -A
The CreateCheckoutResponse doesn't have the getId() function. It has getCheckout() and getErrors(). So you need to:
$checkoutId = $result->getCheckout()->getId();
Reference: https://github.com/square/connect-php-sdk/blob/master/docs/Model/CreateCheckoutResponse.md
Current Solution:
function objectToArray ($object) {
if(!is_object($object) && !is_array($object))
return $object;
return array_map('objectToArray', (array) $object);
}
$result_array = objectToArray($result);
echo '<pre>';
var_dump($result_array); //test to see if any non-zero response to createCheckout() function.
echo '</pre>';
Since I am getting a valid object back, and all I need to do is extract the ID and checkout URL's from the $result object, I used the function above to convert the object to an array, and from here I'll extract the information I need by key => Value pairing. It's ugly, and it doesn't solve why these post API-call functions included with the SDK aren't working, but it's meeting my immediate solution.
If anyone can tell me what actually happened that prevented the SDK function calls from being defined, I'd appreciate it.
I am trying to consume a soap service in php. This is the code I am using
define('APIURL','https://cgorders.com/v2.1/Service.asmx?WSDL');
$client = new SoapClient(APIURL);
$search_query = new StdClass();
$search_query ->CustomerID = CustomerID;
$search_query ->ClientPO = $orderID;
$search_query ->AccessToken = $cgTokem; //AccessToken;
$result = $client->GetOrdersByClientPO($search_query);
//echo "<pre>";print_r($result->GetOrdersByClientPOResult->Orders->OrderID);echo "</pre>";exit;
if(isset($result->GetOrdersByClientPOResult->Orders->OrderID))
{
return($result->GetOrdersByClientPOResult->Orders->OrderID);
}
else
{
return('');
}
I am passing appropriate parameters correctly, did not mention them, for security reasons.
I am getting Call to undefined method soapclient::GetOrdersByClientPO() . Can anybody help?
check available functions by calling $client->::__getFunctions(); and see if GetOrdersByClientPO in the returned list
Soap client was not installed over the server, I was testing. After installation, it worked like a charm.
Thank you.
public function request_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$this->load->library('dropbox', $params);
$data = $this->dropbox->get_request_token(base_url());
$this->session->set_userdata('token_secret', $data['token_secret']);
redirect($data['redirect']);
}
//This method should not be called directly, it will be called after
//the user approves your application and dropbox redirects to it
public function access_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$this->load->library('dropbox', $params);
$oauth = $this->dropbox->get_access_token($this->session->userdata('token_secret'));
$this->session->set_userdata('oauth_token', $oauth['oauth_token']);
$this->session->set_userdata('oauth_token_secret', $oauth['oauth_token_secret']);
redirect('welcome/test_dropbox');
}
//Once your application is approved you can proceed to load the library
//with the access token data stored in the session. If you see your account
//information printed out then you have successfully authenticated with
//dropbox and can use the library to interact with your account.
public function test_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$params['access'] = array('oauth_token'=>urlencode($this->session->userdata('oauth_token')),
'oauth_token_secret'=>urlencode($this->session->userdata('oauth_token_secret')));
$this->load->library('dropbox', $params);
$dbobj = $this->dropbox->account();
print_r($dbobj);
}
Blockquote
i have used Dropbox library https://github.com/jimdoescode/CodeIgniter-Dropbox-API-Library
When i call to function request_dropbox() it gives me error in api "Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\reports\application\libraries\Dropbox.php on line 478"
please help me how to access dropbox files.
Please look at your errors more carefully, it turns out that curl is not enabled on your Xampp environment.
This should help you out to enable CURL and get you going again.
How to enable curl in xampp?
I am using the test code found # http://code.google.com/apis/youtube/2.0/developers_guide_php.html to create a playlist:
$newPlaylist = $yt->newPlaylistListEntry();
$newPlaylist->summary = $yt->newDescription()->setText($desc);
$newPlaylist->title = $yt->newTitle()->setText($title);
// post the new playlist
$postLocation = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
try {
$playlist = $yt->insertEntry($newPlaylist, $postLocation);
}
catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
The playlist is created, but how can I get the id or url of the playlist that was just created?
I have the same problem. I have managed to get a bit further but I still can't get the playlistID. Here is what I did:
instead of:
$playlist = $yt->insertEntry($newPlaylist, $postLocation);
I used :
$playlist = $yt->insertEntry($newPlaylist, $postLocation, 'Zend_Gdata_YouTube_PlaylistListEntry');
But when I try to get the id by $playlist->getPlaylistID() or $playlist->playlistId->text I get the same exception which says :
The yt:playlistId element is not supported in versions earlier than 2.
even if I have set it earlier with $yt->setMajorProtocolVersion(2);
This is a complete and utter hack, I had the same exact problem, so I went into the class at Zend/Gdata/YouTube/PlaylistListEntry.php on line 229 I commented out the if else statement.
/**
* Returns the Id relating to the playlist.
*
* #throws Zend_Gdata_App_VersionException
* #return Zend_Gdata_YouTube_Extension_PlaylistId The id of this playlist.
*/
public function getPlaylistId()
{
/*if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
'element is not supported in versions earlier than 2.');
} else {*/
return $this->_playlistId;
//}
}
I would LOVE for someone to show us how to fix this the right way, but this made it so
function printPlaylistListEntry($playlistListEntry, $showPlaylistContents = false)
{
$this->yt->setMajorProtocolVersion(2);
echo '<br>Title: ' . $playlistListEntry->title->text . "\n";
echo '<br>Description: ' . $playlistListEntry->description->text . "\n";
echo '<br>playlistId: ' . $playlistListEntry->playlistId->text . "\n";
... (from the youtube v2 php api).
will return the playlistid.
Title: therighttitle
Description: therightdescription
playlistId: therightplaylistId
edit: I think this may be a better solution:
if ($this->getMajorProtocolVersion() < 2) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
'element is not supported in versions earlier than 2.');
} else {
return $this->_playlistId;
}
replace the getPlaylistId() function with this, follows the logic of the preceding getDescription function, and its less hacky. Again completely open to critiques on why this is or is not a good idea from the zend people.
You don't need any special hacks to make this work. You just need to explicitly set the protocol version for the $playlist variable, along with the $yt variable. As you stated, set the major protocol version for $yt earlier:
$yt->setMajorProtocolVersion(2);
Then after you initialize $playlist, set the protocol on that as well:
$playlist = $yt->insertEntry($newPlaylist, $postLocation, 'Zend_Gdata_YouTube_PlaylistListEntry');
$playlist->setMajorProtocolVersion(2);
Once you do this, you should be able to get your playlist ID no problem :)
$playlist_id = $playlist->getPlaylistID();