I am trying to use the PHP API, and same example as given in the code
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_search_operations.html#_scrolling
$client = ClientBuilder::create()->build();
$params = [
"scroll" => "30s", // how long between scroll requests. should be small!
"size" => 50, // how many results *per shard* you want back
"index" => "my_index",
"body" => [
"query" => [
"match_all" => new \stdClass()
]
]
];
// Execute the search
// The response will contain the first batch of documents
// and a scroll_id
$response = $client->search($params);
But getting error like this Unknown key for a VALUE_STRING in [scroll].
Currently using Elasticsearch version 6.2.2
Any ideas?
The problem is that you put scroll parameter in json body, but it should be instead in the URL. e.g
index-name/_search?scroll=30s
Don't forget to remove it from $params as well
You may have accidentaly put scroll attribute inside body.
Related
I am trying to send multiple posts to Twilio using Guzzle. My apologizes, I'm very new to guzzle. I have seen some examples where I can set an array of URIs and run the posts in parallel. But I haven't been able to figure out how to use the same URI with different parameters for each request.
The ONLY difference between each call would the the "TO" field. The body, messageSID, and auth would stay the same for each parallel call. I wanted to get this test working then eventually just be able to build the array of anywhere from 1 to 100 TO phone numbers.
Here is my code to send one request:
use GuzzleHttp\Client;
use GuzzleHttp\Promise;
$client = new Client(["base_uri" => "https://api.twilio.com/2010-04-01/Accounts/"]);
$options = array(
'form_params' => [
"Body" => "hello world",
"To" => "+12015551234",
"MessagingServiceSid" => "MGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
],
'auth' => [
"accountsidxxxxxxxxxxx",
"tokenxxxxxxxxxxxxxxx"
]
);
$response = $client->post("ACxxxxxxxxxxxxxxxxxxxxx/Messages.json", $options);
echo $response->getBody();
I'm using an api that has a "range" parameter that can apply to several different parameter items. The range i'm focusing on is "price". I'm using guzzle in laravel and according to the api documentation, the query for this particular parameter should be written like this "&range_facet=price|500|2500|250"...this is broken down into the minimum, maximum, and interval values of the price range parameter. That's not necessarily important to this question. When i try and run this query as is, i get nothing returned. When I remove that particular parameter, i get values but obviously they're not filtered the way i want them to be. When i run this in Insomnia, the pipes are replaced by "%7C", which is obviously (obviously?) not interpreted by the api as it's not how it's waiting for the GET request to be made. How can I insert the pipes into the query so that it calls the correct way?
I've tried to create an additional nested array with the price value being broken up into key value pairs but that didn't work either.
'range_facets' => ['price'['start'=>'500', end=>'2500', 'interval'=>'250']],
$client = new Client();
$result = $client->request('GET', "http://api.example.com", [
'headers' => [
'Host' => 'example-host',
'Content-Type' => 'application/json'
],
'query' => [
'api_key' => 'my_api_key',
'range_facets' => 'price|500|2500|250',
'year' => $year,
'latitude' => '30.170222',
'longitude' => '92.01320199',
'radius' => 500,
'start' => 0,
'rows' => 50
]
]);
I'd like to filter my prices but I need the pipe to be able to do it.
This is exactly how it should be. %7C should be decoded on the server side to | automatically (about query string encoding).
I bet the issue is in different place.
I am using google Classroom google API and Google APIs Client Library for PHP.
I can add announcement, but I cannot add materials.
I would like to add files to Google Drive, but I have errors even with "link"
My code so far:
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setApplicationName("test classroom");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/classroom.courses',
"https://www.googleapis.com/auth/classroom.rosters",
"https://www.googleapis.com/auth/classroom.announcements",
"https://www.googleapis.com/auth/classroom.coursework.students",
"https://www.googleapis.com/auth/classroom.coursework.me",
]);
// $service implements the client interface, has to be set before auth call
$service = new Google_Service_Classroom($client);
$text="some text";
$link="http://someurl";
$glink = new Google_Service_Classroom_Link($link);
$glink->setUrl($link);
$params = [
"text" => $text,
"materials" => [
"link" => $glink,
],
];
$params_obj = new Google_Service_Classroom_Announcement($params);
$service->courses_announcements->create($course_classid, $params_obj);
//tried also with:
$params = [
"text" => $text,
"materials" => [
"link" => ((new Google_Service_Classroom_Material())->setLink($glink)) ,
],
];
the error:
"message": "materials: Link materials must have a URL.",
So off the top, it seems odd here that you are creating params associative arrays at all. The PHP client has methods for adding all parameters, all the way down to the leaf level. So you shouldn't see any arrays in your code. Continue to use the methods instead and it will help clean things up. If you're still having problems, I may have some time to dig on this particular item.
Your limk must be array with three entry
$params = [
"text" => 'Please, do your homeworks until Monday',
"materials"=>['link'=>['url'=>'https://www.examaker.com',
'title'=>'HW',
'thumbnailUrl'=>'https://examaker.com/apps/imgs/logo_40.png']
]
];
I have this code :
$data=$collection1->aggregate(array( '$group'=> array('_id'=>$valoreScelto,'contatore'=>array('$sum'=>1))));
$valoreScelto is a valid field of document MongoDB, that i retry by FORM.
$valoreScelto = trim('$'.$campoSelezionato);
I obtain this error:
Fatal error: Call to a member function aggregate() on string
UPDATE:
The error says: You are trying to access the method "aggregate", in the string (Variable $collection1 have type - string).
You need to check $collection1 (for example var_dump). $collection1 must be Collection (or in mongo extension MongoCollection).
You can get a collection like this:
$yourConnectInDB = new Client(...); // or MongoClient(...);
$db = $yourConnectInDB->selectDatabase('YOUR DB NAME');
$collection1 = $db->selectCollection('YOUR COLLECTION NAME');
Also, in your code you want to use the aggregation like this:
$ops = array( // base array
array(
'$group' => array(
"_id" => $valoreScelto,
"contatore" => array('$sum'=>1),
)
),
// other pipeline
);
$data=$collection1->aggregate($ops);
Read this and this
I tried the above answer as well and it wasn't returning anything. After a lot of trying I figured out that I had missed a keyword without which the above query was not going to work. I am pasting the code below.
$ops = [
[
'$group' => [
"_id" => $valoreScelto,
"contatore" => ['$sum'=>1],
]
]
];
$data=$collection1->aggregate($ops)->toArray();
I am trying top use guzzle to get data from https://idf.intven.com/public_patents. The page loads data with AJAX by making request to https://idf.intven.com/public_patent_listing.json.
I am working on a another site for them that they want to use this data for so I am trying to grab this data with guzzle but I keep getting 500 errors.
$this->client = new Client();
$this->client->post( 'https://idf.intven.com/public_patent_listing.json', [
'verify' => false,
'json' => [
"report_type" => "public_patent_listing",
"queryFields" => [],
"filters" => [],"per_page" => 16,
"from" => 0,
"sort" => "issued_on",
"sort_order" => "desc"
],
]);
Maybe because you are using arrays instead of json objects. Change the square brackets to curly ones for main object and json object in it