I'm building an app using the new Parse PHP SDK. How can in include the user session token inside a ParseQuery?
1 Answer
If you set the ParseSessionStorage in your code, you can make use of the getCurrentUser() method in the SDK.
session_start();
// Init parse: app_id, rest_key, master_key
ParseClient::initialize('xxx', 'yyy', 'zzz');
$storage = new ParseSessionStorage();
ParseClient::setStorage( $storage );
$user = ParseUser::getCurrentUser();
You can then get the session token as follows:
$sessionToken = ParseUser::getCurrentUser()->getSessionToken();
You don't need to pass the session into calls. It will automatically use the session if available.
8 Comments
Learner Always
any simpler way to achieve the same? saw your blogpost for beginners to php+parse as well. Trust me I'm complete beginner
Niraj Shah
This is by far the simplest method to achieve this.
Learner Always
yes, did my own bit of trial and errors, and achieved it. Thanks a lot!
Niraj Shah
@Cristiana214 the library you are using it's the same as the Official Parse PHP SDK. You should update your code to use the Official Parse PHP SDK to make use of the new functions. The library you're using hasn't been updated in over a year.
Cristiana Chavez
@NirajShah how to use the Official Parse PHP SDK with codeigniter framework? that is why i chose the library because it fits to codeigniter.
|