Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Parse
Started by Michael W. Nov 24 2015 01:20 PM

71 replies to this topic
release android ios tvos windows os x lua
[TOPIC CONTROLS]
Page 2 of 3 1 2 3
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

thanks again,it is my fault,i didn't make it clear.in previous post, my code is actually my whole code expect parse.config

I paste my whole code.  all I want is find the objectId that I created in no matter what way

local parse = require('plugin.parse')
parse.config:applicationId("K4wlYq18ueOcW2Fj8uJ1EvcF5TD74QPKZOgoai83")
parse.config:restApiKey("EnWOVpfkESrv4daVA6uFpvztHN2A17yrP2e4eyqd")
parse.config:debugEnabled( true )

parse.request( parse.Object.create, "countertest" )
:data({ yes = 'kkk' } )
:response()


parse.macro.findWhereEqual( 'countertest', 'yes', 'kkk' )

:response(function( ok, res )
    if not ok then
      print('find err', res)
    else
	print('find ok', res.objectId )

    end
  end)

local function cb( ok, res )
print("yes i am in begin of cb function")
  if ok then
print("yes i am in midlle of cb function")
  
  for _, result in ipairs( res ) do

    print( result.objectId )

  end

  end

print("yes i am in the end of cb function")
end

parse.request( parse.Object.query, 'countertest' )
:where( { yes = 'kkk' } ) --The search key query
:response(cb)




it return in simulator console

********************************************************************
** Parse RESPONSE @ 12-14 22:11:34 [1]
********************************************************************
> createdAt: 2015-12-14T22:11:37.782Z
> objectId: 5FBdnB6KK7
********************************************************************
********************************************************************
** Parse RESPONSE @ 12-14 22:11:34 [2]
********************************************************************
> code: 102
> error: Invalid key $eq for find
********************************************************************
find ok nil
********************************************************************
** Parse RESPONSE @ 12-14 22:11:34 [3]
********************************************************************
> results:
>    1:
>       createdAt: 2015-12-14T08:52:00.425Z
>       objectId: 41jmOfO6IG
>       updatedAt: 2015-12-14T08:52:00.425Z
>       yes: kkk
>    2:
>       createdAt: 2015-12-14T08:52:28.765Z
>       objectId: RGwpfMevi8
>       updatedAt: 2015-12-14T08:52:28.765Z
>       yes: kkk
********************************************************************
yes i am in begin of cb function
yes i am in midlle of cb function
yes i am in the end of cb function


code line 11 return

 

> code: 102
> error: Invalid key $eq for find

 

code line 29 return nothing

 

if you have time, feel free to paste the whole code to your pc to run the code.you will see what I see.

this is the code without line number

local parse = require('plugin.parse')
parse.config:applicationId("K4wlYq18ueOcW2Fj8uJ1EvcF5TD74QPKZOgoai83")
parse.config:restApiKey("EnWOVpfkESrv4daVA6uFpvztHN2A17yrP2e4eyqd")
parse.config:debugEnabled( true )

parse.request( parse.Object.create, "countertest" )
:data({ yes = 'kkk' } )
:response()


parse.macro.findWhereEqual( 'countertest', 'yes', 'kkk' )

:response(function( ok, res )
    if not ok then
      print('find err', res)
    else
	print('find ok', res.objectId )

    end
  end)

local function cb( ok, res )
print("yes i am in begin of cb function")
  if ok then
print("yes i am in midlle of cb function")
  
  for _, result in ipairs( res ) do

    print( result.objectId )

  end

  end

print("yes i am in the end of cb function")
end

parse.request( parse.Object.query, 'countertest' )
:where( { yes = 'kkk' } ) --The search key query
:response(cb)




[TOPIC: post.html]
#27

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

The following code is going to show you several ways to make this work, but please remember the following :

 

  • Everything is asynchronous
  • If you create objects with always the same parameters and if you are doing a query with those parameters, then you will get all the objects that share the same values (This was one of your mistake before)
     
    -- ************************************************************************
    -- CREATING OUR OBJECT
    -- ************************************************************************
    local function createObject(value)
        local function objCreatedCallback( ok, res, info )
            if ok == true then
                if res.code and res.error then
                    print("something happen > ", res.code, res.error)
                else
                    print("this is the id of the " .. value .. " object you just created", res.objectId )  
                end
            end
        end

        parse.request( parse.Object.create, "countertest" )
            :data({ name = value } )
            :response(objCreatedCallback)
    end
    
    print("Creating our blue object...")
    createObject("blue")
    
    print("Creating our red object...")
    createObject("red")

    -- ************************************************************************
    -- QUERY ALL
    -- ************************************************************************
    print("Perform a queries to list all 'countertest' object class ")
    
    local function queryCallback( ok, res, info )
        if ok == true then
            if res.code and res.error then
                print("something happen > ", res.code, res.error)
            else
                for _, result in ipairs( res ) do
                   print( result.objectId )
                end
            end
        end
    end
  
    parse.request( parse.Object.query, "countertest" )
        :response(queryCallback)
        
    -- ************************************************************************
    -- QUERY OBJECT TYPE OF COUNTERTEST
    -- ************************************************************************
    print("Perform a queries to find specific instances of an object, for example the blue one... ")
    
    local function queryCallback( ok, res, info )
        if ok == true then
            if res.code and res.error then
                print("something happen > ", res.code, res.error)
            else
                for _, result in ipairs( res ) do
                   print( result.objectId )
                end
            end
        end
    end
  
    parse.request( parse.Object.query, "countertest" )
        :where( { ["name"] = "blue" } )
        :response(queryCallback)


[TOPIC: post.html]
#28

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

thanks again, i am very appreciate your help.

step 1.

I copy all your code replace my main.lua and relaunch simulator

simulator console did show parse response,

but code as below don't work, it didn't print result.objectId,it print nothing

                for _, result in ipairs( res ) do
                   print( result.objectId )
                end

step 2.

1.I know asynchronous mean I must wait some time to get the result.

2.you say don't always create same parameters ,so I only create parameters once and then query.

​this is what I do

​I change class name from countertest to countertest3 and replace "blue" to "ha" and relaunch again only once

it still print nothing

 

step 3.

I delete create function,  only left query function as below is my whole code

local parse = require('plugin.parse')
parse.config:applicationId("K4wlYq18ueOcW2Fj8uJ1EvcF5TD74QPKZOgoai83")
parse.config:restApiKey("EnWOVpfkESrv4daVA6uFpvztHN2A17yrP2e4eyqd")
parse.config:debugEnabled( true )
    print("Perform a queries to list all 'countertest' object class ")
    
    local function queryCallback( ok, res, info )
        if ok == true then
            if res.code and res.error then
                print("something happen > ", res.code, res.error)
            else
                for _, result in ipairs( res ) do
                   print( result.objectId )
                end
            end
        end
    end
  
    parse.request( parse.Object.query, "countertest3" )
        :response(queryCallback)

simulator console still return  same result that I have see many times as blow.

I can see parse response on simulator console ,it mean parse did response result

but ​ code line 13 still dont' work,it didn't print anything

Perform a queries to list all 'countertest' object class
********************************************************************
** Parse RESPONSE @ 12-15 06:10:45 [1]
********************************************************************
> results:
>    1:
>       createdAt: 2015-12-15T03:56:02.038Z
>       name: ha
>       objectId: p01QtAm3yU
>       updatedAt: 2015-12-15T03:56:02.038Z
********************************************************************



[TOPIC: post.html]
#29

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

               
Try replacing this with :
 
for key, value in ipairs( res.results ) do
     print( "MyObject Id", value.objectId )
end


[TOPIC: post.html]
#30

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

it works ,thanks all you guys. i know i have a lot to learn,again ,thanks



[TOPIC: post.html]
#31

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

@wgh92281, my last suggestion prove that if you had put a breakpoint from the beginning of your problem, you would have found the solution right away. Please next time, use a debugger, put a breakpoint and investigate return value. It help you and it help us.



[TOPIC: post.html]
#32

Mgoldberg62401

[GLOBAL: userInfoPane.html]
Mgoldberg62401
  • Contributor

  • 133 posts
  • Corona SDK

Hi Corona Community!  

 

Today I have a question, regarding checking already existing usernames via Parse.

On my login page, I am allowing my user to create an account(username + password).  I am using Parse backend for this.

 

 I need help writing code that will handle if the username they choose to use already exists on my parse user database!  

 

My code so far is below of my account creation file.

 

ALL help is appreciated! Thanks!

 

 

 

  1. --remove status bar
  2. display.setStatusBar( display.HiddenStatusBar )
  3.  
  4.  
  5.  
  6. --require modules
  7. local composer = require "composer"
  8. local scene = composer.newScene()
  9. local parse = require('plugin.parse')
  10. parse.config:applicationId("MY ID HERE")
  11. parse.config:restApiKey("MY REST API KEY HERE")
  12. parse.config:debugEnabled( true )
  13. parse.showStatus = true
  14. local usernameInput
  15. local passwordInput
  16. local bg
  17. local createAccountBtn
  18. local createAccount
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. local function onUsername( event )
  27.     if ( "began" == event.phase ) then
  28.         -- This is the "keyboard appearing" event.
  29.         -- In some cases you may want to adjust the interface while the keyboard is open.
  30.  
  31.     elseif ( "submitted" == event.phase ) then
  32.         -- Automatically tab to password field if user clicks "Return" on virtual keyboard.
  33.         native.setKeyboardFocus( passwordInput)
  34.     end
  35. end
  36.  
  37. local function onPassword( event )
  38.     -- Hide keyboard when the user clicks "Return" in this field
  39.     if ( "submitted" == event.phase ) then
  40.         native.setKeyboardFocus( nil )
  41.     end
  42. end
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. --create account
  50. local function createAccount(event)
  51. if (event.phase == "began") then 
  52.  
  53. parse.request( parse.User.query )
  54.   :where( { username = ""..usernameInput.text } )
  55.   :response(cb)
  56.   
  57.  
  58. --check here if username already exists!
  59.  
  60. --if it doesn't exist, create account!
  61.  
  62. --add account to parse database
  63. parse.request( parse.User.create ) 
  64. :data( { username = ""..usernameInput.text, password = ""..passwordInput.text} )
  65. :response(cb)
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. end
  73. end
  74.  
  75.  
  76.  
  77. --create scene
  78. function scene:create( event )
  79. local group = self.view
  80.  
  81.  
  82.  
  83. bg = display.newRect(display.contentCenterX, display.contentCenterY, 800, 800)
  84. bg:setFillColor( 1, .6, 0 )
  85.  
  86.  
  87. -- Create username text field
  88. usernameInput = native.newTextField( display.contentCenterX, 150, 260, 40 )
  89. usernameInput:setReturnKey( "next" )
  90. usernameInput.placeholder = " Username"
  91.  
  92. group:insert(usernameInput)
  93.  
  94. usernameInput:addEventListener( "userInput", onUsername  )
  95.  
  96.  
  97.  
  98. -- Create password text field
  99. passwordInput = native.newTextField( display.contentCenterX, display.contentCenterY, 260, 40 )
  100. passwordInput:setReturnKey( "go" )
  101. passwordInput.placeholder = " Password"
  102.  
  103. group:insert(passwordInput)
  104.  
  105. passwordInput:addEventListener( "userInput", onPassword )
  106.  
  107.  
  108. -- Create register account button
  109. createAccountBtn = display.newImage("registerBtn.png")
  110. createAccountBtn.x = display.contentCenterX; createAccountBtn.y = display.contentCenterY + 80
  111. createAccountBtn:scale(.15, .1 )
  112.  
  113.  
  114.  
  115.  
  116. end
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. --enter scene
  124. function scene:show( event )
  125. local group = self.view
  126. local phase = event.phase
  127.  
  128.  
  129.    if ( phase == "will" ) then
  130.      
  131.      
  132.      
  133.    elseif ( phase == "did" ) then
  134.  
  135.  
  136. createAccountBtn:addEventListener( "touch", createAccount )
  137.  
  138.  
  139.  
  140.  
  141.  
  142. end
  143. end
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. --exit scene
  153. function scene:exitScene( event )
  154. local group = self.view
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. end
  165.  
  166.  
  167.  
  168.  
  169.  
  170. --destroy scene
  171. function scene:destroyScene( event )
  172. local group = self.view
  173. local phase = event.phase
  174.  
  175.  
  176.  if ( phase == "will" ) then
  177.      
  178.      
  179.      
  180.    elseif ( phase == "did" ) then
  181.    
  182.    
  183.    
  184.    
  185.    
  186.  
  187. end
  188. end
  189.  
  190.  
  191.  
  192.  
  193. scene:addEventListener( "create", scene)
  194. scene:addEventListener( "show", scene)
  195. scene:addEventListener( "hide", scene)
  196. scene:addEventListener( "destroy", scene)
  197.  
  198. return scene


[TOPIC: post.html]
#33

Mgoldberg62401

[GLOBAL: userInfoPane.html]
Mgoldberg62401
  • Contributor

  • 133 posts
  • Corona SDK

@nmichaud  

 

Do you have any advice or solution for my problem? I see your the expert here!  ;) 

 

Thanks



[TOPIC: post.html]
#34

Chribbe

[GLOBAL: userInfoPane.html]
Chribbe
  • Enthusiast

  • 73 posts
  • Corona SDK

Just wanted to say thanks for making this. Works perfectly so far for us!


  • Develephant likes this

[TOPIC: post.html]
#35

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

@Mgoldberg62401, you also creates a specific thread for this (https://forums.coronalabs.com/topic/60626-check-if-parse-username-already-exists-help/). Please always ask a question in one place as it is hard after that for the community to know where to look. Please look at the specific thread you created for an answer...

 

PS: Thanks for the good word, but I am not an expert, the real expert is @develephant who created an amazing plugin.



[TOPIC: post.html]
#36

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,450 posts
  • Corona SDK

@Mgoldberg62401, you also creates a specific thread for this (https://forums.coronalabs.com/topic/60626-check-if-parse-username-already-exists-help/). Please always ask a question in one place as it is hard after that for the community to know where to look. Please look at the specific thread you created for an answer...

 

PS: Thanks for the good word, but I am not an expert, the real expert is @develephant who created an amazing plugin.

 

@nmichaudYou probably know more about its real-world usage than I.  :D Thanks again to helping out.

 

Cheers.



[TOPIC: post.html]
#37

Mgoldberg62401

[GLOBAL: userInfoPane.html]
Mgoldberg62401
  • Contributor

  • 133 posts
  • Corona SDK

 @nmichuad  @develephant

 

 

Hi again! Your advise worked! I now have fully integrated a login and registration system in my app! Thanks for that!

 

HOWEVER, 

 

I have 1 more question!

 

How can I allow files to be shared from device to device that are on my parse database?

 

 I need to allow a user to record his/her voice on their app, and be able to send that to another user of the app via parse.

I know I will need to use the "upload" and "download" parse commands. If you could point me in the right direction or give me some sample code that would be awesome!

 

Thanks!



[TOPIC: post.html]
#38

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

@Mgoldberg62401, there are many ways to do what you want. As it simplest form you could do something like that (again this is a suggestion without knowing the scope of what you want to do)

 

  • Create a "voiceMsg" class in parse
  • Create a "voiceMsg" object and set the parameters details... (destination user Id, play yes/no, etc)
  • Use "parse.upload" to upload your file
  • Use "parse.macro.linkFileToObject" to link it to your newly created "VoiceMsg" object
  • notify your user with the "VoiceMsg" objectId or better simply notify your user that a msg is waiting for him
  • your user do a query on the msg waiting for him
  • download the file
  • do some clean up on "VoiceMsg" object

 

Again, this is just a quick and dirty way of doing this.

 

I hope this help



[TOPIC: post.html]
#39

Mgoldberg62401

[GLOBAL: userInfoPane.html]
Mgoldberg62401
  • Contributor

  • 133 posts
  • Corona SDK

@nmichaud 

 

Thanks for your quick reply!

 

I understand each step clearly, thanks to you!  However, how do I query for the message or audio file through parse?

 

  I don't quite get how the other device that is retrieving the file will be able to query for the message with that specific identifier.  How will the device know what the Object ID is or the unique file URL?

 

If you could please explain this more clearly, or even better provide a code example, that would be much appreciated!

 

 

Thanks!



[TOPIC: post.html]
#40

Mgoldberg62401

[GLOBAL: userInfoPane.html]
Mgoldberg62401
  • Contributor

  • 133 posts
  • Corona SDK

@nmichaud



[TOPIC: post.html]
#41

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

@Mgoldberg62401, In your initial question, you mention that you want one user to send a voice msg to another user. You must have the destination user Object ID for this to work. How you are going to do this part, is really up to you. It depends of how you are building/architect your app and how you find people or friend.

 

Basically, if you know the ObjectId of the user to send the voice msg, you attach this object ID as a parameter of your voiceMsg object. Then your user, knows its own user Object id, therefore the query is not a problem

 

Doing a query is quite straightforward with the object ID. If you link your audio file with your voiceMsg object, you will have the file URL in the result of your query. After that, its just a question of doing a network.download.

At this point, I have gave you lot of hint to investigate and direction to try. I am sorry,  but I do not have time to write some code example for doing this as you must understand I have also work to do :) But I am sure that you should be able to find your way.

 

Hope this help

Nick



[TOPIC: post.html]
#42

Mgoldberg62401

[GLOBAL: userInfoPane.html]
Mgoldberg62401
  • Contributor

  • 133 posts
  • Corona SDK

@nmichaud 

 

Thanks again! I fully understand the steps now! 

 

LAST QUESTION I SWEAR! :)

 

​How would you go about saving a user's object ID when searching for the person?

 

Basically, there will be a search bar that the user can search for users by username.  I am using the parse findUserByUsername and already figured out a way to actually capture the object ID.  However, where can I save the object ID?  I can't have a globals file in my app and save every single user Object Id that someone searches for!

 

How can I save the Object ID for later use when they want to send the audio file?

 

Thanks and I swear this is the last question. lol

 

-Max



[TOPIC: post.html]
#43

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

@Mgoldberg62401, I do not understand the problem you are describing. From my point of view, doing a query on the database should always be mandatory as you have a search on the real data everytime. You should only store what is important for your user. Again I do not know what is your app and how it should work, but I guess that if someone is searching for a specific individual, then you should only store the new friend. And then again, maybe like Facebook, you want to ensure that the user on the other end accept to receive audio files...

 

Now to store your list of friend, there is many ways of doing that. You can either build your own lib or use code that is available on the Corona site.



[TOPIC: post.html]
#44

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,450 posts
  • Corona SDK

Hi @Mgoldberg62401,

 

I'm afraid this topic is moving away from being plugin related and more about application semantics. Any further questions in regards to how to make "systems" should be started in a new thread. Many thanks!

 

Cheers.



[TOPIC: post.html]
#45

Mgoldberg62401

[GLOBAL: userInfoPane.html]
Mgoldberg62401
  • Contributor

  • 133 posts
  • Corona SDK

Below I have my code that handles searching for a user in parse.  

The "if" statement runs fine when the text field's text matches a registered user.  However, when the text field's text doesn't match a registered user, the "else if" statement should run.  However, it doesn't.

 

My question is: ​How can I get the else if statement to run when the text field text doesn't match a registered user?

 

I am guessing there is some kind of debugging method to set as the conditional statement, for example: elseif (value.results == nil) or something along those lines that can detect when no users are returned/found.  Thanks!

 

 

 

 

--search bar function to find user
   local function onSearchUser( ok, res, info )
        if (ok == true) then
           
           for key, value in ipairs( res.results ) do
 
 
           if (value.username == searchInput.text) then
                -- user found!
 
print("USER FOUND!")
 
print( "Push notification target is: "..searchInput.text  )
 
gamesettings.pushNotificationTarget = ""..searchInput.text
loadsave.saveTable(gamesettings, "settings.json")
 
elseif (value.username ~= searchInput.text) then
 
native.showAlert( "No User Found", searchInput.text.." does not exist!",  { "" }  )
 
 
end
      end
   end
end
  
  
  parse.macro.findUserByUsername( ''..searchInput.text)
  :response(onSearchUser)


[TOPIC: post.html]
#46

Mgoldberg62401

[GLOBAL: userInfoPane.html]
Mgoldberg62401
  • Contributor

  • 133 posts
  • Corona SDK

@develephant @nmichaud



[TOPIC: post.html]
#47

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

Hi @Mgoldberg62401 you should really start a new thread as @develephant ask. This is not the  right thread to ask questions related to an app your building and LUA related question.

 

We are in a busy schedule with our app, therefore I will not be able to help you as quickly as before.



[TOPIC: post.html]
#48

julio.salheb

[GLOBAL: userInfoPane.html]
julio.salheb
  • Observer

  • 1 posts
  • Corona SDK

Just want to say thank you @develephant for the great plugin.

 

Your plugin will acelerate our development.

 

I hope I can contribute with the community in the future.



[TOPIC: post.html]
#49

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,450 posts
  • Corona SDK

Hi Julio,

 

You are very welcome, and thank you for taking the time to let me know.

 

Happy New Year.



[TOPIC: post.html]
#50

spjnowak

[GLOBAL: userInfoPane.html]
spjnowak
  • Contributor

  • 160 posts
  • Corona SDK

Here's a surprise - Parse is closing down its hosted service in 12 months time!

 

http://blog.parse.com/announcements/moving-on/

 

They are providing the server software as open source and a migration tool to move your Parse database to MongoDB.




[topic_controls]
Page 2 of 3 1 2 3
 
[/topic_controls]

Also tagged with one or more of these keywords: release, android, ios, tvos, windows, os x, lua