Retrieve Data from a response object in PHP - php

New to php (used C and VB years ago) Using a Temboo API for Ebay, I'm attempting to retrieve messages from our eBay account. Although the API says it will return a JSON string, when executing it returns an object. Using var_dump(get_defined_vars($getMemberMessagesResults)); returns this relevant information:
'getMemberMessagesResults' =>
object(eBay_Trading_GetMemberMessages_Results)[7]
protected 'outputArray' =>
array (size=1)
'Response' => string '{"#xmlns":"urn:ebay:apis:eBLBaseComponents","Timestamp":"2021-07-29T21:52:49.047Z","Ack":"Warning","...
protected 'lowercaseKeyMap' =>
array (size=1)
'response' => string 'Response' (length=8)
I am trying to extract the information 'Response'=> string('xlmns":"urn:ebay:apis"... information so that I can then process to put in a database. But, I cannot figure out how to reference this information to extract it. I've tried lots of references but so far I've been stumped. I realize the information is probably there somewhere but being new to PHP I'm feeling stumped. Thanks in advance for your assistance.

Related

Parsing Google Service Objects in PHP

I feel a bit silly, but I have no clue how to parse the objects that Google returns from their API in PHP, can someone shine a light on it?
So for instance, if I request:
print_r($job->getState());
I get this:
Google\Cloud\Scheduler\V1\HttpTarget Object
(
[uri:Google\Cloud\Scheduler\V1\HttpTarget:private] => http://example.com/cron-check.php
[http_method:Google\Cloud\Scheduler\V1\HttpTarget:private] => 1
[headers:Google\Cloud\Scheduler\V1\HttpTarget:private] => Google\Protobuf\Internal\MapField Object...
So how in the world do I get the uri value out of this object?
Googling the Object you're receiving in response, I found the source code for it:
https://github.com/googleapis/google-cloud-php/blob/master/Scheduler/src/V1/HttpTarget.php
Looking at this, there appears to be a simple getter method for the URI property. Try:
$job->getState()->getUri();

Trouble adding intent to bot

When trying to add an intent to a bot, I'm getting the following:
{"message":"The resource 'SomeBotThatDefinitelyExists' referenced in resource 'TestBot' was not found. Choose another resource."}
I'm calling the putBot method, and passing the intents below:
`'intents' => [
[
'intentName' => 'SomeBotThatDefinitelyExists',
'intentVersion' => '1',
],
[
'intentName' => 'TestingTheBot',
'intentVersion' => '1'
]
]`
I am absolutely positive that I've successfully created the offending intent. I can see it in the AWS panel, and via the api. The only difference that I can see between the two intents is that the second intent, 'TestingTheBot' has been included in a previous version of the bot. I am able to add it via the api without issue, but, again, trying to add SomeBotThatDefinitelyExists returns the error above.
For anyone with the same issue, I discovered that intents created with putIntent don't have a version. After creating an intent, you must call createIntentVersion. You can then obtain the latest version from the intent returned by the API. That should be the version you use to set the intentVersion property when adding an intent to a bot.

Laravel dispatch plain json on queue

I have 2 simple questions overall. Im currently looking into some event handling in Laravel and would like to use RabbitMQ as my event store. Therefor i installed this package to start with: https://github.com/php-enqueue/enqueue-dev
To get started i registered it and i am able to push messages on to RabbitMQ:
$job = (new Sendemail())->onQueue('email')->onConnection('interop');
dispatch($job);
The problem however is that Laravel pushes a certain format on the queue and i can't figure out how to change that. An example message would be:
{
"job":"Illuminate\\\\Queue\\\\CallQueuedHandler#call",
"data":{
"command":"O:29:\\"Acme\\Jobs\\FooJob\\":4:{s:11:\\"fooBar\\";s:7:\\"abc-123\\";s:5:\\"queue\\";N;s:5:\\"delay\\";N;s:6:\\"\\u0000*\\u0000job\\";N;}"
}
}
So the question is, how can i change this? The main reason on this is that the consumer side is not even a PHP application which also can not interpret the PHP serialized model. Therefor im looking for a way to push a plain JSON object instead.
From the other hand i would also like to understand how you could build a custom listener? For the listener the same thing happens. Laravel tries to read the method but when i push plain JSON this will never work. Isn't there a way to register a handler on a topic and do further handling of the payload of the message within the handler itself?
There is a simple way for your purpose:
First install this package for rabbit:
vladimir-yuldashev/laravel-queue-rabbitmq
and in controller:
Queue::connection('rabbitmq')->pushRaw('{you can generate a json format here}', 'queue_name');
you can generate a json and put in this command.
There's a laravel-queue library that works with the php-enqueue library you linked to make it compatible with Laravel's built in queue system that Florian mentioned.
By default, it will still use a serialized object, but I think that can be overridden. If you look in Queue.php, createObjectPayload() on line 130 in the core Laravel Framework, that's where the job is being serialized.
If you extend the Queue class in the laravel-queue library, you should be able to change createObjectPayload to look something like this:
protected function createObjectPayload($job, $queue)
{
$payload = $this->withCreatePayloadHooks($queue, [
'displayName' => $this->getDisplayName($job),
'job' => 'Illuminate\Queue\CallQueuedHandler#call',
'maxTries' => $job->tries ?? null,
'timeout' => $job->timeout ?? null,
'timeoutAt' => $this->getJobExpiration($job),
'data' => [
'commandName' => $job,
'command' => $job,
],
]);
return array_merge($payload, [
'data' => [
'commandName' => get_class($job),
'command' => json_encode(clone $job),
],
]);
}
That should JSON encode the job data instead of serializing it. You may even be able to remove the encoding altogether, as I think it's already JSON encoded somewhere up the chain.

test API with phpunit laravel 5.2

so I have created a test class in /test directory
in a testExample function, I have store input and output JSON string into a variable.
converted input and output strings to array by using
json_decode(inputstring, true); json_decode(outputstring, true);
I have used following to test this API
$this->json('POST', 'api/v1/tagging', $input, ['Content-Type' => 'application/json'])
->seeJson([
'conversion_specs' => ["post_engagement"],
]);
Where conversion_specs: ["post_engagement"] is one of the section of output json
how could I assert it and it is printing too much data after hitting
./vendor/bin/phpunit command
I think it's going wrong, can anyone help me to check an API with expected value.

Taobao API - isv.permission-api-package-empty

I'm new with Taobao API and I'm not Chinese. I need to obtain category list and items from Taobao.com.
I'm using Yii and this extension: http://www.yiiframework.com/extension/topsdk4yii/
I have Api key and Api Secret, I'm trying to make a query and a receive this error:
object(stdClass)[16]
public 'code' => int 11
public 'msg' => string 'Insufficient isv permissions' (length=28)
public 'sub_code' => string 'isv.permission-api-package-empty' (length=32)
I make query in this way ( in SiteController.php -> function actionIndex() ):
Yii::import('application.extensions.taobao.request.*');
$request = new ShopGetRequest();
$request->setNick('my_username_from_taobao');
$request->setFields('sid,cid,title,nick,desc,bulletin,pic_path,created,modified');
$shop = Yii::app()->top->execute($request);
var_dump($shop);
I found some explanation here http://open.taobao.com/support/question_detail.htm?id=496 but I can't find how to fix this.
Please help me.
Thanks in advance.
You can't fix it from your application
you have to tell to the Api owner to white-list your server ip address if not done your application will not be able to make requests to taobao api.
The error means your application has not applied for the required permissions. You can do this from the application menu (providing an explanation of the application plus reason for applying in Chinese), after which they will handle your application within 3 working days.

Categories