How to use parse-server with the PHP SDK ?
Hello!
I have a Parse server running and working well with my Swift code. Now, I would like to connect this MongoDB server to my PHP code. But I can't find any documentation on how to do that.
For the moment, I have this code :
ParseClient::initialize( $app_id, $rest_key, $master_key );
How to update it to add my server URL ?
Thanks! Axel
This is without testing (as I haven't started migration testing yet), but I would imagine that it follows a similar line to the other platforms which would be to change the following in the ParseClient.php to point your server.
final class ParseClient { /** * Constant for the API Server Host Address. */ const HOST_NAME = 'https://api.parse.com';
@MarkCYoung Thanks for your answer.
That's what I did until now. I also set up the different keys on my parse-server but also in my PHP configuration file... And I always get the message "unauthorized" on all of my requests. Still trying to fix that, but I'm opened to your suggestions!
EDIT : My bad, forgot to restart my Parse server after setting the new keys. Now, I'm getting a new error "Bad Request", but I'm working on fixing it :+1:
My bad, forgot to restart my Parse server after setting the new keys. Now, I'm getting a new error "Bad Request", but I'm working on fixing it
This is due to the default route for the parse-server residing on '/parse' where the Parse PHP SDK utilises '/1'. Refer to this line in ParseClient.php:24 const API_VERSION = '1';. Either change your route in your parse-server instantiation:
// Mount the Parse API server middleware to /1
app.use('/1', parseServer);
Or modify your ParseClient.php to use '/parse'.
I assume this will be fixed in the next release of the SDK.
I need to update the PHP SDK with a method for changing the server URL... I missed it.
@fraxool would you be willing to share your source code on how you got your swift code connected to your parse server?
Waiting for method to change server URL ... thanks ! Posted here this issue at PHP SDK.
Sorry for the late guys. I wrote a complete answer on StackOverflow to fix that :
http://stackoverflow.com/a/35132450/4569921
@gfosco any updates to the php sdk you can push please?
So I did the sort of hack today and changed some values in ParseClient.php
const HOST_NAME = 'https://xxxxxx.herokuapp.com';
and
const API_VERSION = 'parse';
My app key, rest key and master key all match up whats on the server, and I'm able to do a CURL request to get the data im trying to in php, but every time I try it in php it returns "unauthorized"
I have checked my keys and restarted my parse server to make sure nothing silly was happening and since the CURL request worked I'm not sure what to do next.. any ideas?
Heroku log
2016-02-09T21:25:52.623179+00:00 heroku[router]: at=info method=GET path="/parse/classes/UserTag?where=%7B%22gamelID%22%3A%22afcd60f2-f9b2-4c5f-9148-1de46713552b%22%7D" host=xxxxxx.herokuapp.com request_id=18d1c97b-6ffc-4942-ac16-b0b2c20a6504 fwd="173.230.155.65" dyno=web.1 connect=0ms service=6ms status=403 bytes=273
any ideas?
Anyone have any ideas.. im pretty stuck from moving forward from my comment above ^^^
that hack enabled me to read values from my parse-server, but the save() function doesn't seem to work in the current php sdk...
@occurrentarts what did you change to make this work.. I'm currently stuck on the php side of things :(
@gateway
- first i updated my parse php sdk to the newest
- then i opened ParseClient.php and set the hostname equal to my server: const HOST_NAME = 'http://parseserver-bv###-env.elasticbeanstalk.com';
- then i changed the API_Version key like so: const API_VERSION = 'parse';
- then i opened ParseFile.php and added my file key to the path ( line 227? ) $url = ParseClient::getAPIUrl().'files/my_file_key/'.$this->getName();
- then i was hitting a 413 error whenever i tried to upload content above 1mb, so i followed this process to expand the limit on my parse-server:
http://stackoverflow.com/questions/18908426/increasing-client-max-body-size-in-nginx-conf-on-aws-elastic-beanstalk
finally i have object saving and image and audio uploads working with the PHP SDK.
I updated the PHP SDK to version 1.2.0, you can now change the server URL after initialization:
ParseClient::setServerURL('https://myserver.com/parse');
thanks @gfosco does it continue to require the fileKey or is that taken care of by parse-server?
@occurrentarts fileKey should only be required on the parse-server side, for legacy files hosted by Parse.
@gfosco thanks for the update.. I'm getting an unauthorized response when doing a query.
Here is simple php script..
require 'autoload.php';
use Parse\ParseClient;
$app_id = "X5hlsQoD2uY0Za2zQUyy";
$rest_key = "X3eX9XwzzJpkmMfjLR8E";
$master_key = "GhgoqbRnKkHN9ctsPAYu";
ParseClient::initialize( $app_id, $rest_key, $master_key);
ParseClient::setServerURL('https://xxxxxx.herokuapp.com/parse');
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;
try {
$query = new ParseQuery("UserTag");
$query->equalTo("gameID", "241e84cf-055e-43b8-a5ad-75c7c87c75ea");
$results = $query->find();
echo "Successfully retrieved " . count($results) . " scores.";
// Do something with the returned ParseObject values
for ($i = 0; $i < count($results); $i++) {
$object = $results[$i];
echo $object->getObjectId() . ' - ' . $object->get('factualID');
}
} catch (\Exception $e){
echo $e->getMessage();
}
Heroku logs..
at=info method=GET path="/parse/classes/UserTag?where=%7B%22gameID%22%3A%22241e84cf-055e-43b8-a5ad-75c7c87c75ea%22%7D" host=xxxxxx.herokuapp.com request_id=a7eddbef-d40f-4d2e-93a7-edf160ff6dcc fwd="173.230.155.65" dyno=web.1 connect=4ms service=8ms status=403 bytes=273
My keys from index.js thats running on my parser server
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://xxx:[email protected]:43694/awslike',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'X5hlsQoD2uY0Za2zQUyy',
javascriptKey: process.env.CLIENT_KEY || '6HkIJlJxgVD9N7Qsn9cw',
masterKey: process.env.MASTER_KEY || 'GhgoqbRnKkHN9ctsPAYu',
clientKey: process.env.CLIENT_KEY || '6HkIJlJxgVD9N7Qsn9cw',
restAPIKEY: process.env.RESTAPI_KEY || 'X3eX9XwzzJpkmMfjLR8E',
fileKey: process.env.FILE_KEY || 'PQAvUKDvBf0rg7GMhnZT',
filesAdapter: new S3Adapter(
process.env.AWS_ACCESS_KEY || 'xxxxxxx',
process.env.AWS_SECRET_ACCESS_KEY || 'xxxxxxx',
{bucket: process.env.AWS_BUCKET_NAME || 'xxxxx', bucketPrefix: "", directAccess: true}
)
});
I dont care about the keys being posted here, these are just temp but I wanted to display that they match the php ones..
Printing out the url from the ParseClient gives me this..
https://xxxxx.herokuapp.com/parse/classes/UserTag?where=%7B%22gameID%22%3A%22241e84cf-055e-43b8-a5ad-75c7c87c75ea%22%7D
returned value: unauthorized.
Either im missing something simple or something is broke. @gfosco any thoughts on how I could help debug this further.. ?
EDIT: I should mention JS and CURL requests work.
According to that code, you're passing restAPIKEY instead of restAPIKey... My advice is to remove all keys except master from the ParseServer. No more javascriptKey, clientKey, restAPIKey, or dotNetKey.
@gfosco ok this is a bit confusing since ill need the js key for my js code, php for rest api, and master.. also our app will be using the client key.. So ideally I need these keys unless Im missing something.
making the change for index.js to
restAPIKeY: process.env.RESTAPI_KEY || 'X3eX9XwzzJ34MfjLR8E',
Gave me the same results.
Disabling clientKey and javascriptKey and clientKey in index.js solved the problem.
However this begs the question then on the JS side of things you have to embed your master key which could bee seen in source code if your doing front end stuff, isnt this a security issue? See concern at #352
`
Parse.initialize("X5h34242uY034Uyy", "6H342gVD234Qsn9cw");
Parse.serverURL = 'https://xxxxx.herokuapp.com/parse'
`
btw thank you for taking the time with this.
You don't embed the master key anywhere. It's just that with parse-server, you don't need client keys, the app id is sufficient identification. They don't add any extra security on parse-server, since they are provided together in visible client code.