I am building a social app like TikTok or Instagram.
Probably the most important thing about the creation of this app is the back and front end communicating with each other. That’s how users will be able to upload posts, send messages, follow each other, etc. and how I’ll be able to check if a function returns true or false and what to do with the given result(s) etc.
Right now the only communication I have between the two is show the username of the user logged in. The username shows but if I want to show other things, like messages, following lists, posts etc. how would I do that ?
This should mostly be about the network.* API and backend knowledge, isn’t it? A while ago, I tried building a quiz game and that was the case. I’d suggest handling many things on the backend and using Solar2D as the frontend tool.
Since you can show the username of the logged in user, you can go on and request other things related to that user as well. It should be the same.
That’s OK but since you already have a mechanism in place that can verify user / password, the rest can also be done the same way.
I assume your login process looks something like this: 1- Username / password entered. 2- Login pressed. 3- Username / password match is checked. a. Check failed - show error, go back to 1. b. Check success - show home / profile page.
So what you need to do is, after step 3-b, query the other table that contains user information like how many followers they have, how many they follow, profile picture etc.
Something like this: SELECT * from userInfo WHERE userId = test
My login and register pages are based on button clicks. So whenever the user goes to the profile page, I want them to see their details (or if it’s someone else’s page that users stuff).
You’d need your PHP script to return some data so you can use it to create your application. I got something like this for one of my projects. By the way, this is really the easy part. You should look more into backend stuff for this instead of frontend. If you can return some data from network.request(), it’s Solar2D knowledge from there on.
You may also want to take a look at this:
and this:
local function listenerRetrieveProfile(event)
if (event.isError) then
print "is error"
else
print (event.response)
local decoded, pos, msg = json.decode( event.response )
if (not decoded) then
print "not decoded"
else
userData = decoded
print (userData[1].name)
end
end
end
local params = {}
params.headers = headers
params.body = "actionType=retrieveProfile&userID=" .. playerID
network.request( "http://www.yourpage.com/getProfile.php", "POST", listenerRetrieveProfile, params )
Lol yeah that’s where my problem is. Because I have an entire project built with PHP that shows it correctly. But I’ll try to do it with the stuff you recommended.
I don’t know why you deleted it but saw your reply. Since you have it all built up and running with PHP, you can share us sample JSON response so we can suggest stuff for you to do.
You can start by packing up $username and $email into a JSON and return that. If you could do that successfully, network listener method that you set up for network.request() call would catch that so you can build up on that.
local URL = "http://192.168.1.37/hashmobile/bootstrap.php?username=" .. userName ;
--local URL="http://localhost:8080/corona/fetch.php?usr="..namee
local response = http.request(URL)
if response == nil then
print("No Dice")
else
local data = json.decode(response)
print (data);--This part gives error
end
I get a result but it says that I am not logged in.
Like I said before, you have to look for returning data through JSON. Take a look at that and take a look at the sample code I shared. That’s the key part in your problem. You have to return encoded JSON data from your backend code. Please take a look at the links I shared in the post below: