简体   繁体   中英

How to use Parse SDK with Angular 7

I'm trying to do a GET request on a Parse backend but i have a 403 response from the server. I tried to follow these instructions but i still have the issue.

Here's the configuration of my service :

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import * as Parse from 'parse';


Parse.initialize('MY APP ID', 'MY MASTER KEY ID'); // use your appID & your js key
(Parse as any).serverURL = 'https://MYURL/parse'; // use your server url


@Injectable({
  providedIn: 'root'
})
export class BackofficeService {

  constructor(private http: HttpClient) {}

  public getStores(): Observable<any> {
    return this.http.get(Parse.serverURL + '/classes/Stores');
  }

I tried to add an empty paramater for the jskey (because i used master key instead of JS key) but it didn't work.

Parse.initialize('MY APP ID', '', 'MY MASTER KEY ID'); // use your appID & your js key

You are trying to use the Rest API of the Parse server, but you configure it with the SDK.

As you configure the SDK and you have it, I really recommend you to use it. Here is how to get all object of stores.

var Stores = Parse.Object.extend("Stores");
var query = new Parse.Query(Stores);
query.find().then(function(results) {
  console.log(results);
});

I resolved my issue by using what Julien gave me and modifying my service into a promise :

  public getStores(): Promise <any> {
  const Stores = Parse.Object.extend('Stores');
  const query = new Parse.Query(Stores);
  return query.find()
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM