user3634054
user3634054

Reputation: 50

parse-php-sdk Fatal error: Uncaught exception 'Parse\ParseException' with message 'unauthorized'

I have double, triple checked the keys, the javascript sdk works great, but when I try to connect with the php sdk, i get Fatal error: Uncaught exception 'Parse\ParseException' with message 'unauthorized' when i try to login a user or do anything

require ("parse-php-sdk-master/autoload.php");
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;
use Parse\ParseClient;
ParseClient::initialize("secret","secret","secret");
ParseClient::setServerURL('https://serveraddress.herokuapp.com','parse');

I am using the most recent version of the php-sdk, an alternative server running the javascvript sdk, connects and works fine.

Upvotes: 1

Views: 663

Answers (1)

Cliffordwh
Cliffordwh

Reputation: 1430

You might find the keys are right but you not passing it on the constructor in parse-server. Make sure its in the parse-server config.

You can also try passing your REST_KEY in the initialize on both the php client side and through parse-server.

 ParseClient::initialize('YOUR_APP_ID', 'YOUR_REST_KEY', 'YOUR_MASTER_KEY');

Update for Heroku:

You need to add all the optional keys: restAPIKey, dotNetKey, clientKey, javascriptKey, to index.js as part of the initialization. Then you must set values for ALL of them. If even one of them is not set, restAPIKey is not enforced.

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '',
  serverURL: process.env.SERVER_URL || 'http://localhost:1337',
  javascriptKey: process.env.JAVASCRIPT_KEY || '',  //** add this line no need to set values, they will be overwritten by heroku config vars
  restAPIKey: process.env.REST_API_KEY || '', //** add this line
  dotNetKey: process.env.DOT_NET_KEY || '', //** add this line
  clientKey: process.env.CLIENT_KEY || '', //** add this line
});

Upvotes: 2

Related Questions