[英]facebook sdk 3.0 login with android activity class
由於以前使用該片段的Facebook登錄名,並且效果很好,因此隨着需求的變化現在可以通過活動登錄Facebook,因此,我們有正常的android按鈕,單擊該登錄對話框將出現,用於用戶交互,以提供用戶名和密碼,當登錄成功后,用executeme請求獲取用戶詳細信息。完成所有代碼,但是當單擊按鈕對話框時未出現,而是在onsessionstate上,將日志顯示為
首先顯示OPENING比顯示LOGIN FAILED CLOSED
在facebook應用程序開發站點中提到的所有在facebook中登錄所需的步驟均已執行,並且所有必填類和元數據信息也都在andriod清單文件中給出。
這里是用於登錄的活動類
public class ResgistrationApp extends Activity {
EditText username,password,name,nickname,email,phone;
Button Registertauky,fb_connect;
com.facebook.Session fbSession;
ImageView user_image;
private UiLifecycleHelper uihelper;
private Session.StatusCallback sessioncallback=new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
// TODO Auto-generated method stub
Log.e("Sessionstate", ""+state);
if(session.getState()==SessionState.OPENED)
{
makeuserdetailsrequest(session);
}
}
};
private Request.GraphUserCallback graphcallback=new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// TODO Auto-generated method stub
Log.e("FB RES", ""+response);
Log.e("UID", ""+user.getId());
}
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
setContentView(R.layout.activity_resgistration_app);
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.primus.taukyresigstration",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
uihelper=new UiLifecycleHelper(this, sessioncallback);
uihelper.onCreate(savedInstanceState);
username=(EditText) findViewById(R.id.register_usernameone);
password=(EditText) findViewById(R.id.register_password);
name=(EditText) findViewById(R.id.register_username);
nickname=(EditText) findViewById(R.id.register_nickname);
email=(EditText) findViewById(R.id.register_email);
phone=(EditText) findViewById(R.id.register_phone);
Registertauky=(Button) findViewById(R.id.Registertauky);
user_image=(ImageView) findViewById(R.id.register_user_picture);
fb_connect=(Button) findViewById(R.id.facbook_getinfo);
fbSession=new Session(this);
fbSession.addCallback(sessioncallback);
//This going to register the tauky server
Registertauky.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
//This button click going to connect to the facebook
fb_connect.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(fbSession.isOpened())
{
fbSession=Session.getActiveSession();
//do the fetching of user details..
}
else
{
fbSession=Session.openActiveSession(ResgistrationApp.this, true, sessioncallback);
}
}
});
}
//--------------------------------------------------------------------------------------------------------------//
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
uihelper.onActivityResult(requestCode, resultCode, data);
//Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
class LoginretrieveTask extends AsyncTask<Void, Void, Void>
{
Session session;
public LoginretrieveTask(Session fbsession) {
// TODO Auto-generated constructor stub
session=fbsession;
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
return null;
}
}
protected void makeuserdetailsrequest(Session session) {
// TODO Auto-generated method stub
Request user_request=Request.newMeRequest(session, graphcallback);
user_request.executeAsync();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
uihelper.onResume();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
uihelper.onPause();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
uihelper.onDestroy();
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
uihelper.onSaveInstanceState(savedInstanceState);
}
}
Log.e(“ Sessionstate”,“” + state); 這里顯示LOGIN FAILED CLOSED。
和清單文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.primus.taukyresigstration"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.primus.taukyresigstration.ResgistrationApp"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name">
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/appid"/>
</application>
</manifest>
所以任何人都可以指出我做錯了什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.