【问题标题】:How to display the facebook details automatically in android app as long as there is an active access token?只要有活动的访问令牌,如何在 android 应用程序中自动显示 facebook 详细信息?
【发布时间】:2014-11-20 19:21:14
【问题描述】:

我正在创建一个使用 facebook 登录的 android 应用程序。我为此目的使用图形 api。我想显示登录用户的个人资料图片、姓名和位置。我有一个方法用于获取个人资料信息。我希望每次打开我的应用程序时都显示详细信息,而无需每次调用​​登录方法。即。只要有活动的访问令牌,我想自动显示详细信息。如何做到这一点?

我的登录方法工作正常。只要有活动的访问令牌,如何自动显示详细信息?

【问题讨论】:

    标签: android facebook facebook-graph-api-v2.0


    【解决方案1】:

    使用 Session 对象使用您的 Facebook 访问令牌和令牌到期日期创建一个新会话

    【讨论】:

      【解决方案2】:

      您可以将用户信息存储在Shared Preferences

      例如;登录后可以保存用户数据

      // this Application Context  
         SharedPreferences preferences  = PreferenceManager.getDefaultSharedPreferences(this);      
         SharedPreferences.Editor editor = preferences.edit();
      
         editor.putString("name",retrievedName);
      
         editor.putString("picture",retrievedPicture);
      
         editor.putString("location",retrivedLocation);
      
         editor.commit();
      

      然后您可以轻松检查用户是否已通过身份验证 getString(String key, String defValue)

       //if it is null login again
       String name = preferences.getString("name",null);
      

      或者您也可以使用 sqlite,但如果您正在开发原生应用程序,最好使用facebook android sdk

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多