2016-12-09 12 views
1

私はこれをgoogledしましたが、私が得るのは、期限切れのFacebookページトークンを生成しない方法です。Androidが期限切れにならないようにするfacebook user token

シナリオはこれです: 私はアンドロイドアプリケーションからユーザーにログインします。次に、トークンを受信すると、そのトークンはサーバーに送られます。今、私がしたいことはこれです: 私はそのトークンを期限切れにしたくないので、ユーザーにアプリケーションから再度ログインする必要はありません。これは可能ですか?

+0

SharedPreference変数を使用し、ユーザーがログインしているかどうかを保存します。ユーザーがログインしていない場合は、再度ログインを要求しないでください。 –

+0

@NigamPatroそして5ヶ月後にトークンの有効期限が切れた? –

+0

一度ログインしたユーザーは、どのようなトークンが必要ですか? –

答えて

0

Globals.java

import android.app.Application; 
import android.content.SharedPreferences; 
import android.preference.PreferenceManager; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 

/** 
* Created by Furkan on 28.10.2016. 
*/ 

public class Globals extends Application{ 
    @Override 
    public void onCreate() { 
     super.onCreate(); 


    } 

    private String token; 
    public void setConfig(String key, String value) { 
     try { 
      SharedPreferences spref =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); 
      SharedPreferences.Editor spref_edit = spref.edit(); 
      spref_edit.putString(key, value); 
      spref_edit.commit(); 
     } catch (Exception e) { 
      Log.i("FD", e.getMessage()); 
     } 

    } 

    public String getConfig(String key) { 
     SharedPreferences spref =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); 
     return spref.getString(key, ""); 
    } 

    public void delConfig(String key) { 
     SharedPreferences spref =  PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); 
     SharedPreferences.Editor spref_edit = spref.edit(); 
     spref_edit.remove(key); 
     spref_edit.commit(); 
    } 


    public void clearConfig() { 
     SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); 
     SharedPreferences.Editor spref_edit = spref.edit(); 
     spref_edit.clear(); 
     spref_edit.commit(); 
    } 

    public void setToken(String token) { 
     this.token = token; 
     setConfig("token", token); 
    } 
} 

このクラスは、トークンを保存するのに役立ちます。

あなたのメインクラスで行う必要があります。

Globals g; 

トークンに達すると、そのように保存する必要があります。

g.setToken(token); 

また、保存されたトークンがある場合はログイン画面をスキップしたい場合は、次のようにする必要があります。

if(!g.getConfig("token").isEmpty()){ 
     Intent intent = new Intent(Main.this, BlaBlaBla.class); 
     startActivity(intent); 

Good Luck!

+0

ありがとうございます。今、トークンが期限切れになっている場合、ログインせずに別のトークンを取得する方法は? –

+0

@MiljanVulovic私はそれが期限切れではないと思う。あなたはシナリオを教えていただけますか?私はそれについて考えるだろう –

関連する問題