Hi, I began using Google App Engine to create an Application Server for my 
mobile application. I began by hosting PHPMyAdmin onto my Application 
Server to manage my Google Cloud server following this link here: 
https://cloud.google.com/sql/docs/phpmyadmin-on-app-engine. The problem is, 
now I want to create a way for my Android Application to communicate with 
my Application Server. I simply want to be able to store data into my 
Application Server where I have hosted an instance of Google Cloud, and 
also retrieve data from my instance of Google Cloud. However, I can't seem 
to communicate with my application server at all. This is what I did after 
following the above steps:

1. I created a Request Builder where I can send a Firebase Cloud Messaging 
Token from my device to the Application Server like so:

public class NotificationInstanceService extends FirebaseInstanceIdService {
 private static final String TAG = "NotificationInstance";
 @Override
 public void onTokenRefresh() {
 //Getting registration token
 String refreshedToken = FirebaseInstanceId.getInstance().getToken();
 //Displaying token on logcat
 Log.d(TAG, "Refreshed token: " + refreshedToken);
 sendRegistrationToServer(refreshedToken);
 }

 private void sendRegistrationToServer(String token) {
 //You can implement this method to store the token on your server
 //Not required for current project
 OkHttpClient client = new OkHttpClient();
 //Create the request body
 RequestBody body = new FormBody.Builder().add("Token", token).build();
 //Know where to send the request to
 Request request = new Request.Builder().url("<Application Server 
URL>/register.php")
 .post(body)
 .build();
 //Create
 try {
 client.newCall(request).execute();
 } catch (IOException e) {
 e.printStackTrace();
 }

 }

This seems to be working. 
client.newCall(request.execute();
seems to go through without any errors.

1. I created a script called register.php which looks something like this:

    if (isset($_POST["Token"])) {
           $_uv_Token=$_POST["Token"]; 
           $conn = mysqli_connect("/cloudsql/<database name url>","root","",
"FCM") or die("Error connecting"); 
           $q="INSERT INTO users (Token) VALUES ( '$_uv_Token') " 
              ." ON DUPLICATE KEY UPDATE Token = '$_uv_Token';"; 
      var_dump(mysqli_query($conn,$q)); 
      mysqli_query($conn,$q) or die(mysqli_error($conn)); 
      mysqli_close($conn); 
    } else { 
        var_dump($_REQUEST); 
    }

This would be a simple way to connect to my database and update the users 
database I created using the PHPMyAdmin console page. 


3. After I created the script, I simply called 
appcfg.py update .
in my directory, which I would assume redeploys my instance with 
register.php created and I try to send my REST call via my Android 
Application. I notice in the Google Cloud Console, logs are posted but I 
don't see my data being uploaded to the users database. I am not sure where 
I am going wrong. Any help would be much appreciated. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/b9704706-d0fa-41a6-a941-8b79a0049873%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • [google-appengine] H... Stephen Chan

Reply via email to