我已經花了2天才能使這個工作,但我不能,我不斷收到這個異常com.parse.ParseRequest$ParseRequestException: invalid session token
。 我不是一個有經驗的android開發者,這是我第一次解析,所以如果你能發佈詳細的答案,我會很感激。SignUp活動Android上的會話令牌無效(解析後端)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".ParseApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="@string/parse_app_id" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="@string/parse_client_key" />
<activity
android:name=".ParseStarterProjectActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".SignUp"
android:label="@string/title_activity_sign_up" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
SignUp.java
package com.parse.starter;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
public class SignUp extends Activity {
private Button sign_up_b;
private TextView email;
private TextView password;
private TextView password_conf;
private TextView firstName;
private TextView lastName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_up);
sign_up_b = (Button)findViewById(R.id.email_sign_up_button);
email = (TextView)findViewById(R.id.email);
password = (TextView)findViewById(R.id.password);
password_conf = (TextView)findViewById(R.id.confirm_password);
firstName = (TextView)findViewById(R.id.first_name);
lastName = (TextView)findViewById(R.id.last_name);
sign_up_b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
attemptSignUp();
}
});
}
private void attemptSignUp(){
// Create the ParseUser
ParseUser user = new ParseUser();
// Set core properties
user.setUsername(email.getText().toString());
user.setPassword(password.getText().toString());
user.setEmail(email.getText().toString());
// Set custom properties
user.put("lName", lastName.getText().toString());
user.put("fName", firstName.getText().toString());
// Invoke signUpInBackground
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(com.parse.ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
//Intent i = new Intent(getBaseContext(),Splash.class);
//startActivity(i);
} else {
e.printStackTrace();
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sign_up, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
signup.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.parse.starter.SignUp">
<ScrollView android:id="@+id/sign_up_form" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="@+id/sign_up_infos" android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<EditText android:id="@+id/first_name" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/prompt_first"
android:maxLines="1"
android:singleLine="true" />
<EditText android:id="@+id/last_name" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/prompt_last"
android:maxLines="1"
android:singleLine="true" />
<EditText android:id="@+id/email" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/prompt_email"
android:inputType="textEmailAddress" android:maxLines="1"
android:singleLine="true" />
<EditText android:id="@+id/password" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/prompt_password"
android:inputType="textPassword"
android:maxLines="1" android:singleLine="true" />
<EditText android:id="@+id/confirm_password" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/prompt_confirm_password"
android:inputType="textPassword"
android:maxLines="1" android:singleLine="true" />
<Button android:id="@+id/email_sign_up_button" style="?android:textAppearanceSmall"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:text="@string/action_sign_up"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
我試圖在這個職位的答案,但我一直得到相同的異常 com.parse.ParseRequest$ParseRequestException: invalid session token
謝謝Salah,但我找到了解決我的問題的方法。 – Kallinikos