Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Quick Start Code: Incorrect Namespace and Method #734

Closed
manuelricci opened this issue Aug 21, 2024 · 2 comments
Closed

Error in Quick Start Code: Incorrect Namespace and Method #734

manuelricci opened this issue Aug 21, 2024 · 2 comments
Assignees

Comments

@manuelricci
Copy link

manuelricci commented Aug 21, 2024

Hi,

I'm not sure if this is the right place to report this issue. If it's not, please feel free to close this issue and let me know where I should post it.

In the code snippet provided in the "Get Started" section to start using Algolia, there are some errors:

<?php
require(__DIR__."/vendor/autoload.php");

use Algolia\AlgoliaSearch\SearchClient; 

$url = "https://dashboard.algolia.com/sample_datasets/movie.json";
$response = file_get_contents($url);
$records = json_decode($response, true);

$client = SearchClient::create("ID4NV3D7MX", "xxx");
$index = $client->initIndex("your_index_name"); 

$index->saveObjects($records, [ 'autoGenerateObjectIDIfNotExist' => true ]);

use Algolia\AlgoliaSearch\SearchClient will throw an error because SearchClient doesn't exist in that namespace. From v4 onwards, the correct namespace is Algolia\AlgoliaSearch\Api\SearchClient.

Furthermore, initIndex is no longer available in the new class, so it must be removed.

Maybe is better to show the Get Started example available in the PHP docs.

Have a nice day

@Fluf22
Copy link
Contributor

Fluf22 commented Aug 21, 2024

Hey @manuelricci 👋🏻

Thank you very much for your report! We are in the process of updating our website to reflect these changes.
We will close this issue when it's done.

Btw, I took the liberty to remove your admin API key from the code snippet you shared, but it's still available in the issue history.
I'd suggest you go to your account and rotate it from the settings page! 😁

Thanks

@Fluf22 Fluf22 self-assigned this Aug 21, 2024
@manuelricci
Copy link
Author

Ops! Thank you very much for the edit and for the quick reply.

Have a good day

@Fluf22 Fluf22 closed this as completed Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants