Intel XDK : Parse.com integration “Unauthorized”

我的梦境 提交于 2020-01-24 21:45:16

问题


I am very new to Intel XDK and i try to make a very simple app like this in that video tutorial: Using Services Datafeed in App Designer.

But instead of the specific service from Rotten Tomatoes i want to integrate a database i have in Parse.com. For that i followed this video tutorial: "Integrating a New Service"

"[https]://software.intel.com/en-us/html5/videos/integrating-a-new-service",

and at the end the response was: "Unauthorized".

Then i found only this answer which comes from Intel's HTML5 Development Forums. I did not get anything either with this. The response was again: "Unauthorized".

And now i am confused and disappointed because:

  1. I can't find other resources to help my self
  2. I don't want to do it someone else instead of me, but
  3. Without a full example, how is supposed to make it to learn?

My code now is similar with this in video: "Integrating a New Service"

In apiconfig.json

{
  "MyService": {
    "name": "The external service",
    "description": "A great API with an external service",
    "dashboardUrl": "https://parse.com",
    "auth": "key",
    "signature": "apiSecret"
  }
}

In MyService.js

(function (credentials) {
  var exports = {};

  exports.ServiceObject = function(params) {
    var url = 'https://api.parse.com/1/classes/ServiceObject';
    params['apiKey'] = credentials.apiKey;
    url = url + '?' + $.param(params);
    return $.ajax({url: url, type: 'GET'});
  };

  return exports;
})

And in MyService.json

{
"endpoints": [
  {
    "name": "classes",
    "dashboardUrl": "https://parse.com/docs/rest",
    "methods": [
      {
        "MethodName": "ServiceObject",
        "Synopsis": "Show the entries",
        "parameters": [
          {
            "Name": "objectId",
            "Required": "N",
            "Default": "",
            "Type": "string",
            "Description": "The object ID"
          },
          {
            "Name": "text",
            "Required": "N",
            "Default": "",
            "Type": "string",
            "Description": "The text"
          }
        ]
      }
    ]
  }
]
}

Can someone help me more? In whatever way he thinks best.

Thank you all

Edit:

After the following answer, my problem solved.

"MyService.js" file after the correction is:

(function (credentials) {
  var exports = {};

    exports.ServiceObject = function(params) {
    var url = 'https://api.parse.com/1/classes/ServiceObject';
    return $.ajax({
            url : url,
            headers : {
            'X-Parse-Application-Id' : credentials.apiKey,
            'X-Parse-REST-API-Key' : credentials.apiSecret
            }
        });
    };

  return exports;
})

@ user1736947: Your answer was concise and precise, exactly what i needed. Certainly in the future I will need a lot of help, but for now I can go on my self-education thanks to you. Thank you very much.


回答1:


The way the authentication keys are accepted is different for different services. The example in the video.. rottentomatoes.. it accepted keys as a url parameter, so we append the key to the url and send it. However, seems like parse wants the keys in the headers (according to this)

So the equivalent ajax call will be something like :

 exports.ServiceObject = function(params) {
   var url = 'https://api.parse.com/1/classes/ServiceObject';
   return $.ajax({
     url : url,
     headers : {
      'X-Parse-Application-Id' : credentials.apiKey,
      'X-Parse-REST-API-Key' : credentials.apiSecret
     }
  });

This might not fix everything but it will move you a step beyond the authorization issue. Let me know if you are able to retreive the class this way. To get a particular row entry, append the url with params.objectID.

Also, the XDK services tab has a parse-similar service ... kinvey. It also allows you to create a database online and retreive it.



来源:https://stackoverflow.com/questions/25630215/intel-xdk-parse-com-integration-unauthorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!