I'm trying to get new BatchJob (https://developers.google.com/adwords/api/docs/guides/batch-jobs) up and running, however missing one part.
Docs says:
The good news is that your client library of choice will have a
utility that handles constructing and sending the request for you. The
example below uses the BatchJobHelper utility from the Java client
library.
However PHP library is missing that Helper and any method that should do that...
Anyone had any luck sending request to API using BatchJob? I can't find any working example anywhere.
Thanks!
In the branch experimental they are rewriting the API. It seems that the BatchJobHelper is missing still (current day of write this), see my issue in github requesting it.
For get BatchJobs you should use the BatchJobService class, which is instantiated from the adword service. This is a example snippet:
$batch_job_service = $adWordsServices->get($session, 'BatchJobService', 'v201605', 'cm');
try
{
/** #var BatchJobReturnValue $result */
$result = $batch_job_service->mutate($operations);
}
catch(ApiException $e)
{
echo $e->getMessage() . PHP_EOL;
}
if(!empty($result) && $result instanceof Google\AdsApi\AdWords\v201605\cm\BatchJobReturnValue)
{
$batch_job = reset($result->getValue());
}
else
{
echo 'Result is empty or no valid';
}
If you are using composer to load the new v201603 version of adwords you will need to also adjust your composer file to map the utils since they are duplicated across the other versions for some reason.. Not sure why they did this. you should be able to find the class you need with the following path. Hope this helps.
{
"require": {
"googleads/googleads-php-lib": "8.3.0"
},
"autoload": {
"classmap": [
"vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/Util/v201601"
]
}
}
Related
I discovered JSON Schema today it looks to be 100% fitting my needs, but it's actually driving me nuts with one of the most basic cases. Before creating this post, I obviously did my best to follow existing documentation and looked on the internet trying to find something helping.
Stack : PHP7 - justinrainbow/json-schema 2.0.5
Here is the schema :
{
"description":"UserCreate",
"type":"object",
"properties":{
"login":{
"type":"string",
"required":true
},
"idAsc":{
"type":"string",
"required":true
}
},
"required":[
"login",
"idAsc"
]
}
As you can see I am using both required definition (boolean and array), just to be sure I am using the good one, I also tried with only array and or boolean with the same result.
Here is the data
{
"login":"email#email.com"
}
I am expecting the following code to detect the lack of the required idAsc parameter.
$validator = new JsonSchema\Validator;
$validator->check($data, $schema);
if ($validator->isValid() == false)
echo("Missing something");
else
echo("Good");
But this code keep printing "Good”… I am definitely missing something about JSON Schema.
Thank's for your help, best regards.
I finally make it work, after debugging step by step the implementation of JSON Schema I was using :
First of all, I loaded the JSON Schema myself, the example given in the Github repo look to be broken for me (https://github.com/justinrainbow/json-schema):
$data = json_decode(file_get_contents('data.json'));
// Validate
$validator = new JsonSchema\Validator;
$validator->check($data, (object)['$ref' => 'file://' . realpath('schema.json')]);
I was not able to find any call to file_get_contents or relatives inside the library during my step by step debug. For this reason I decided to load the schema myself instead of giving the path to it:
function getSchema($filePath) {
// NOT WORKING -> return json_decode(file_get_contents($filePath), true);
return json_decode(file_get_contents($filePath));
}
$data = json_decode($rest->getRequest()->getBody());
$schema = $this->getSchema(realpath('controllers/schemas/userCreate.json'));
$validator = new JsonSchema\Validator;
$check_return = $validator->check($data, $schema);
Please pay attention to the commented line in the getSchema function, if you use json_decode with true as 2nd parameter it's not going to work either, the schema has to be an object and not an array !
Now everything is working like a charm for me ;)
Best regards,
It seems to be an issue of the validator implementation you use. This validation must fail. You can try it out with other implementations.
This is the code I'm using.
<?php
require_once('init.php');
if ($_POST) {
\Stripe\Stripe::setApiKey("xxxxxxxxxxxxx");
$error = '';
$success = '';
try {
if (!isset($_POST['stripeToken']))
throw new Exception("The Stripe Token was not generated correctly");
$charge = \Stripe\Stripe_Charge::create(array("amount" => 100, //995
"currency" => "eur",
"card" => $_POST['stripeToken']));
$success = 'Your payment was successful.';
}
catch (Exception $e) {
$error = $e->getMessage();
}
}
?>
Why am I getting the error
"Fatal error: Class 'Stripe\Stripe_Charge' not found in"
I was pulling my hair out on this one as well, but finally found the solution.
From what I found out older versions of PHP (<5.3) did not use namespaces. To get around this PSR-0* converted underscores to directory names. This created a messy interface for Composer. Now with PHP 5.3 and higher namespaces have been added. Composer now uses PSR-4 which supports namespaces but does not convert underscores to directories. Therefore, if you are using the newer preferred PSR-4, you need to use the new method. Therefore, your line:
$charge = \Stripe\Stripe_Charge::create(...);
needs to become:
$charge = \Stripe\Charge::create(...);
You can double check to see what version of PSR your Stripe module is using by opening the /vendor/stripe/stripe-php/composer.json file. Mine shows:
"autoload": {
"psr-4": { "Stripe\\" : "lib/" }
},
which clearly states that I am using PSR-4.
Here is some good reading on the subject: https://mattstauffer.co/blog/a-brief-introduction-to-php-namespacing
*PSR stands for PHP Standards Recommendation
I discovered that neither UsageRecord.php nor UsageRecordSummary.php were available in my stripe-php/lib directory and likewise not initiated in my stripe-php/init.php. I went and grabbed them from https://github.com/stripe/stripe-php/blob/master/lib/
Using Composer to install. adam-paterson/oauth2-stripe. Not sure if this is missing there.
Hi I am new to cassandra database. I am trying to do a project in codeigniter with cassandra database. I have downloaded the phpcassandra files through below link
https://github.com/mauritsl/php-cassandra.
When I am trying to autoload my casssandra.php in codeigniter I got Non-existent class: Cassandra error. Why I got this error and how to solve the issue?
You will need to create a wrapper for it if you wish to use it as a library.
I would suggest you take the composer route.
You can check on packagist for a suitable library.
If you use this particular library phpcassa this is how you would go about getting it to work in Codeigniter.
composer.json
{
"require": {
"php": ">=5.3.0",
"thobbs/phpcassa": "1.1.0"
}
}
index.php
require "../composer/autoload.php";
system/core/codeigniter.php
// Where codeigniter starts to load the Main Controller
// $cassandraDB will be in the GLOBAL scope, so you may want to write a wrapper
$cassandraDB = new ConnectionPool('localhost');
// Then right after this
// if (class_exists('CI_DB') AND isset($CI->db))
// {
// $CI->db->close();
// }
$cassandraDB->close();
User Model
implement it how you wish in your models
public function __construct()
{
//YOU MAY NEED TO PASS $cassandraDB AS A DEPENDANCY!!
$this->users = new ColumnFamily($cassandraDB, 'Standard1');
}
<?php include '../src/class.seostats.php';
try
{
$url = new SEOstats($_GET['url']);
$url->print_array('Google','json');
}
catch (SEOstatsException $e)
{
die($e->getMessage());
}
?>
http://code.google.com/p/seostats/
I want run this but:
$url = new SEOstats($_GET['url']);
is error is for example ['url'] ['mywebpage.com'] or ["mywebpage.com"] error is recurrent in two versions
In first line i have 'home/myuser/public_html/class.seostats.php';
¿Any ideas?
I am the author of the SEOstats package and highly recommend to not use the reference on code.google.com. As stated on the project's start page, you should use the Github pages instead.
My 2nd recommendation is that you should use the dev branch code (which is actually stable - but not yet declared as such): https://github.com/eyecatchup/SEOstats/tree/dev
And finally: Let me get that right: Are you trying to initialize a SEOstats instance as
$url = new SEOstats($_GET['url']['mywebpage.com']); ?
This is at least, what your question suggests. And if that is the case, you should better start here: http://php.net/manual/en/reserved.variables.get.php to understand the example codes of SEOstats.
I am trying to use a SOAP Client-Server in my computer and it doesn't look like it is going to work, I am getting this error Error Fetching Http Headers when I try to run my SOAP Client.
I have been looking and the solution that I have encountred is to increase the default_socket_timeout from 60 to 120 seconds and it doesn't work for me, also I have seen another solution that is putting the vhost in my apache KeepAlive Off and that didn't work.
The WSDL is working fine because I try to use it in another computer and it work.
I am running PHP Version 5.3.5-1ubuntu7.4 in Linux Mint using Zend Framework, I hope some of you can help me fix this thank you.
I'm sorry but I don't know what you are using to set up your SOAP service.....
If you can give more information about your SOAP service (poss Zend_Soap given the Zend Framework tag) etc that would be great.
Also, as a quick alternative, you say you've looked at the WSDL on another computer, perhaps try the application in an alternative environment to ensure it's not an environment issue.
May be a simple issue with your client-server code.
UPDATE: Ok so I realised the example I mentioned yesterday wasn't fully implemented so I've hacked something together quickly that you can try to see if it works in your environment.
The code is a mix of something I found here (an example of Zend_Soap_Server) and something from another SO question here (an example of a basic SOAP service test).
I've tested it at my end using ZF 1.11 and the example I'm outlining uses the default Application path you get with a new ZF project (e.g models are in directory application/models so the model shown is headed up Application_Model_Classname).
If it works, you can tweak accordingly....if it doesn't work we can try something else.
Start by creating a new SOAP controller and set the class up like this:
<?php
class SoapController extends Zend_Controller_Action
{
public function init()
{
ini_set("soap.wsdl_cache_enabled", "0"); //disable WSDL caching
$this->_helper->layout()->disableLayout(); //disable the layout
$this->_helper->viewRenderer->setNoRender(); //disable the view
}
public function indexAction ()
{
if (isset($_GET['wsdl'])) {
//return the WSDL
$this->handleWSDL();
} else {
//handle SOAP request
$this->handleSOAP();
}
}
private function handleWSDL ()
{
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setComplexTypeStrategy($strategy);
$autodiscover->setClass('Application_Model_SoapService');
$autodiscover->handle();
}
private function handleSOAP ()
{
$server = new Zend_Soap_Server(null,
array('uri' => "http://YOURDOMAIN/soap?wsdl"));
$server->setClass("Application_Model_SoapService");
$server->handle();
}
public function testAction()
{
$client = new Zend_Soap_Client("http://YOURDOMAIN/soap?wsdl");
try {
echo $client->testMethod('test');
} catch (Exception $e) {
echo $e;
}
}
}
In the class above, the WSDL is automatically generated using Zend_Soap_Autodiscover with a SoapService.php file at application/models/SoapService.php used as the template. Note the DocBock comments above each method in your target class are integral to this process.
Next create the SoapService.php file in the default models folder:
<?php
class Application_Model_SoapService
{
/**
* testMethod
*
* #param string $string
* #return string $testSuccess
*/
public function testMethod(string $string)
{
$testSuccess = 'Test successful, the message was: ' . $string;
return $testSuccess;
}
}
If all is working as it should be you can visit:
http://YOURDOMAIN/soap?wsdl
to see the WSDL and visit:
http://YOURDOMAIN/soap/test
to get a success message with the string you specified in the client request within the testAction() code in the SoapController class as part of the message.
Let me know if it's working or not and we can go from there.
I'll be able to have another look on Monday.