SignUp活动Android上的会话令牌无效(解析后端)

时间:2015-08-21 09:54:20

标签: java android xml session parse-platform

我已经花了两天时间让这个工作起来但是我不能,我一直得到这个例外com.parse.ParseRequest$ParseRequestException: invalid session token。 我不是一个经验丰富的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

2 个答案:

答案 0 :(得分:0)

您需要在Login \ Signup视图控制器中注销用户。

在viewDidLoad中尝试:

ParseUser.getCurrentUser().logOut();

答案 1 :(得分:0)

为了将来的参考,我所要做的就是从模拟器中卸载应用程序而不是再次运行它,问题就解决了。