parse.com-php-library icon indicating copy to clipboard operation
parse.com-php-library copied to clipboard

Calling Parse from within Wordpress Plugin

Open amrsd opened this issue 12 years ago • 13 comments
trafficstars

I'm trying to create a Wordpress plugin to retrieve/save some information as administration portal for Mob Application Based system.

$parse = new parseRestClient(array('appid' => 'SredRwevZcx8OrYyv6vPhfIa9aELhN54d1hSHxna','restkey' => 'uvs45j1tLjboVMSX8BobNYtHR8YxNU4XyANN9oZz')); $params = array('className' => 'Class1','objectId' => 'cQVmP3VW3J'); $request = $parse->get($params); //////////Gives Error

It give an error message which is "ERROR: response code was 0 with message:"

amrsd avatar Aug 17 '13 19:08 amrsd

cause your doing it wrong ( read the docs ) ..

  • first you should have the parseConfig.php file with the code :
class parseConfig{

    const APPID = '';
    const MASTERKEY = '';
    const RESTKEY = '';
    const PARSEURL = 'https://api.parse.com/1/';
}
  • then you should get your data like this :
$dataToGet = new parseQuery('Class1');
$result = $dataToGet->get('cQVmP3VW3J');
  • now to check for the returned data
var_export($result);

zaherg avatar Aug 17 '13 19:08 zaherg

It gave me the following error

"Fatal error: Class 'parseQuery' not found in C:\DevTools\InstantWP_4.3\iwpserver\htdocs\wordpress\wp-content\plugins\MD-PollParse\MD-PollParse.php on line 17"

Here is Line 17 : "$dataToGet = new parseQuery('Class1');"

Where the definition of the class should be ?

amrsd avatar Aug 17 '13 21:08 amrsd

have you include/require parse.php in your code ?

it would be nice if you put your full code, to check

zaherg avatar Aug 18 '13 07:08 zaherg

Hello Mhmd, I tried a Wordpress plugin & installed it on InstantWP running on windows 8 64bit. I added my code on a function called "catify" on admin-settings.php file. Attached the full plugin. When this plugin is activated & catify function got executed, Gives the following error Array ( [method] => PUT [requestUrl] => classes/Class1/cQVmP3VW3J [data] => Array ( [QuestionID] => Q555 ) )Fatal error: Uncaught ParseLibraryException: [0]: thrown in C:\DevTools\InstantWP_4.3\iwpserver\htdocs\wordpress\wp-content\plugins\wordpress-parse-plugin\inc\classes\parse.php on line 180

Date: Sun, 18 Aug 2013 00:34:44 -0700 From: [email protected] To: [email protected] CC: [email protected] Subject: Re: [parse.com-php-library] Calling Parse from within Wordpress Plugin (#108)

have you include/require parse.php in your code ?

— Reply to this email directly or view it on GitHub.

amrsd avatar Aug 18 '13 22:08 amrsd

as you can see you didnt catch the exception Uncaught ParseLibraryException

try{
 $dataToGet = new parseQuery('Class1');
 $result = $dataToGet->get('cQVmP3VW3J');
} catch(ParseLibraryException $e){
 echo $e->getMessage();
}

zaherg avatar Aug 19 '13 05:08 zaherg

Thanks Mhmd for your support. changed the code to the following try{ $dataToGet = new parseObject('Class1'); $result = $dataToGet->get('cQVmP3VW3J'); echo $result->data; $dataToGet->__set('QuestionID','Q555'); $dataToGet->update(cQVmP3VW3J); } catch(ParseLibraryException $e){ echo $e->getMessage(); } However, not nothing happens, no exceptions thrown but nothing happens also. Here is the outcome after executing this code, "Array ( [method] => GET [requestUrl] => classes/Class1/cQVmP3VW3J ) " No changes take place on the Parse.com when I checked the Data Browser

Date: Sun, 18 Aug 2013 22:19:02 -0700 From: [email protected] To: [email protected] CC: [email protected] Subject: Re: [parse.com-php-library] Calling Parse from within Wordpress Plugin (#108)

as you can see you didnt catch the exception Uncaught ParseLibraryException

try{ $dataToGet = new parseQuery('Class1'); $result = $dataToGet->get('cQVmP3VW3J'); } catch(ParseLibraryException $e){ echo $e->getMessage(); }

— Reply to this email directly or view it on GitHub.

amrsd avatar Aug 19 '13 06:08 amrsd

Actually I'm wondering if the connection between my code & Parse.com is established

From: [email protected] To: [email protected] Subject: RE: [parse.com-php-library] Calling Parse from within Wordpress Plugin (#108) Date: Mon, 19 Aug 2013 06:30:23 +0000

Thanks Mhmd for your support. changed the code to the following try{ $dataToGet = new parseObject('Class1'); $result = $dataToGet->get('cQVmP3VW3J'); echo $result->data; $dataToGet->__set('QuestionID','Q555'); $dataToGet->update(cQVmP3VW3J); } catch(ParseLibraryException $e){ echo $e->getMessage(); } However, not nothing happens, no exceptions thrown but nothing happens also. Here is the outcome after executing this code, "Array ( [method] => GET [requestUrl] => classes/Class1/cQVmP3VW3J ) " No changes take place on the Parse.com when I checked the Data Browser

Date: Sun, 18 Aug 2013 22:19:02 -0700 From: [email protected] To: [email protected] CC: [email protected] Subject: Re: [parse.com-php-library] Calling Parse from within Wordpress Plugin (#108)

as you can see you didnt catch the exception Uncaught ParseLibraryException

try{ $dataToGet = new parseQuery('Class1'); $result = $dataToGet->get('cQVmP3VW3J'); } catch(ParseLibraryException $e){ echo $e->getMessage(); }

— Reply to this email directly or view it on GitHub.

amrsd avatar Aug 19 '13 06:08 amrsd

first can you please format your code first there is nothing called data to echo your code should be :

try{        
    $dataToGet = new parseObject('Class1');     
    $result = $dataToGet->get('cQVmP3VW3J');        
    var_export($result->results); // the returning data is JSON formated string
    $dataToGet->__set('QuestionID','Q555');     
    $updateResult = $dataToGet->update(cQVmP3VW3J);
    var_export($updateResult); // the returning data is JSON formated string with the updatedAt value

} catch(ParseLibraryException $e){          
    echo $e->getMessage();      
    }

zaherg avatar Aug 19 '13 09:08 zaherg

Thnx Mohmd, Applied it but still nothing happens, only this is displayed "Array ( [method] => GET [requestUrl] => classes/Class1/cQVmP3VW3J ) " Date: Mon, 19 Aug 2013 02:06:40 -0700 From: [email protected] To: [email protected] CC: [email protected] Subject: Re: [parse.com-php-library] Calling Parse from within Wordpress Plugin (#108)

first can you please format your code

first there is nothing called data to echo

your code should be :

try{
$dataToGet = new parseObject('Class1');
$result = $dataToGet->get('cQVmP3VW3J');
var_export($result->results); // the returning data is JSON formated string $dataToGet->__set('QuestionID','Q555');
$updateResult = $dataToGet->update(cQVmP3VW3J); var_export($updateResult); // the returning data is JSON formated string with the updatedAt value

} catch(ParseLibraryException $e){
echo $e->getMessage();
}

— Reply to this email directly or view it on GitHub.

amrsd avatar Aug 19 '13 11:08 amrsd

& there is no change in the DB

From: [email protected] To: [email protected] Subject: RE: [parse.com-php-library] Calling Parse from within Wordpress Plugin (#108) Date: Mon, 19 Aug 2013 11:10:53 +0000

Thnx Mohmd, Applied it but still nothing happens, only this is displayed "Array ( [method] => GET [requestUrl] => classes/Class1/cQVmP3VW3J ) " Date: Mon, 19 Aug 2013 02:06:40 -0700 From: [email protected] To: [email protected] CC: [email protected] Subject: Re: [parse.com-php-library] Calling Parse from within Wordpress Plugin (#108)

first can you please format your code

first there is nothing called data to echo

your code should be :

try{
$dataToGet = new parseObject('Class1');
$result = $dataToGet->get('cQVmP3VW3J');
var_export($result->results); // the returning data is JSON formated string $dataToGet->__set('QuestionID','Q555');
$updateResult = $dataToGet->update(cQVmP3VW3J); var_export($updateResult); // the returning data is JSON formated string with the updatedAt value

} catch(ParseLibraryException $e){
echo $e->getMessage();
}

? Reply to this email directly or view it on GitHub.

amrsd avatar Aug 19 '13 11:08 amrsd

1- do you have a records in the DB ? 2- i have put the update in the wrong way ( so am sorry, i just copy and past the code without reading and check what you want to do ) so the right code for update is :

try{        
    // $dataToGet = new parseObject('Class1');    // this is used only for CURD
    $dataToGet = new parseQuery('Class1');    // we use parseQuery for the query and parseObject for CURD actions
    $result = $dataToGet->get('cQVmP3VW3J');        

    var_export($result->results); // the returning data is JSON formated string

    // now to update the data we do it like this :
    $dataToGet2 = new parseObject('Class1');    
    $dataToGet2->QuestionID = 'Q555'; 
    // unless "QuestionID" is a relation type then you should 
   // $dataToGet2->QuestionID = $dataToGet2->dataType('relation', array ( 'QuestionClass', 'Q555' ));

   $updateResult = $dataToGet2->update('cQVmP3VW3J');
    var_export($updateResult); // the returning data is JSON formated string with the updatedAt value

} catch(ParseLibraryException $e){          
    echo $e->getMessage();      
    }

my last advice for you is to read the codes inside the test directory which explain everything

zaherg avatar Aug 19 '13 15:08 zaherg

hey if it works, i hope you close it ..

thanks

zaherg avatar Aug 21 '13 17:08 zaherg

Nope

Thank You & My Best Regards, Amr El-Dessouky

On ٢١‏/٠٨‏/٢٠١٣, at ٧:٣٠ م, "mhd zaher ghaibeh" [email protected] wrote:

hey if it works, i hope you close it ..

thanks

— Reply to this email directly or view it on GitHub.

amrsd avatar Aug 21 '13 19:08 amrsd