locked
Using Parse REST APIs RRS feed

  • Question

  • I know that you will recommend me to download Parse .Net SDK.

    But the problem is that it uses Tasks which are only available in .Net 4.5

    The older versions of .Net are not supported.

    That is why I am going to use parse REST APIs.

    Having a problem in understanding.

    Here is how to create parse object:

    https://parse.com/docs/rest#objects-creating

    curl -X POST \
      -H "X-Parse-Application-Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
      -H "X-Parse-REST-API-Key: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" \
      -H "Content-Type: application/json" \
      -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
      https://api.parse.com/1/classes/GameScore

    I don't know how to add "-d" string(JSon) to the request.

    I tried and here is my code:

            Using client As New WebClient
                Dim values As New NameValueCollection
                values("X-Parse-Application-Id") = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                values("X-Parse-REST-API-Key") = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
                values("Content-Type") = "application/json"
                Dim response = client.UploadValues("https://api.parse.com/1/classes/GameScore", values)
                Dim str = System.Text.Encoding.Default.GetString(response)
            End Using

    And it is returning this error: (401) Unauthorized


    Allow time to reverse.




    • Edited by Abdu Rahman Thursday, March 26, 2015 3:11 PM
    Thursday, March 26, 2015 12:08 PM

Answers

  • :(

    But I got the answer and want to help the others.

            Dim request As WebRequest = WebRequest.Create("https://api.parse.com/1/classes/GameScore")
            request.Headers("X-Parse-Application-Id") = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            request.Headers("X-Parse-REST-API-Key") = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
            request.ContentType = "application/json"
            request.Method = "POST"
            Dim bytes = System.Text.Encoding.GetEncoding("UTF-8").GetBytes("{""score"":1337,""playerName"":""Sean Plott"",""cheatMode"":false}")
            Dim stream = request.GetRequestStream
            stream.Write(bytes, 0, bytes.Count)
            stream.Close()
            Dim response = request.GetResponse
            Dim stream2 = response.GetResponseStream
            Dim bytes2(response.ContentLength - 1) As Byte
            stream2.Read(bytes2, 0, bytes2.Count)
            stream2.Close()
            response.Close()
            Dim s = System.Text.Encoding.Default.GetString(bytes2)
            MsgBox(s)


    Allow time to reverse.


    • Edited by Abdu Rahman Thursday, March 26, 2015 3:11 PM
    • Proposed as answer by Cor Ligthert Thursday, March 26, 2015 3:11 PM
    • Marked as answer by Abdu Rahman Thursday, March 26, 2015 3:12 PM
    Thursday, March 26, 2015 3:10 PM