2011-08-04 1 views
0

アンドロイドで顔の本を統合しました。私はキーストロークを生成したアプリケーションでハッシュキーを生成しました。エミュレータで正常に動作しています。私は別のPCの2つの異なるエミュレータで私のAPKをテストしました。デバイスで実行しようとすると、ログインに失敗したことが示されます:無効なキーです。 私はあなたが私は何をすべきかを私に提案してくださいすることができAndroid facebook integration loginfailed:実デバイスで無効な鍵

keytool -export -alias zitapp -keystore "C:\Users\sreeni\Desktop\pramod\zit.keystore" | openssl sha1 -binary | openssl enc -a -e 

以下のようにハッシュキーを生成しています。

package com.zit; 

import java.util.Locale; 
import java.util.StringTokenizer; 

import org.json.JSONException; 
import org.json.JSONObject; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.TextView; 

import com.facebook.android.AsyncFacebookRunner; 

import com.facebook.android.BaseDialogListener; 
import com.facebook.android.BaseRequestListener; 
import com.facebook.android.DialogError; 
import com.facebook.android.Facebook; 
import com.facebook.android.FacebookError; 

import com.facebook.android.SessionEvents; 
import com.facebook.android.SessionStore; 


import com.facebook.android.Util; 
import com.facebook.android.SessionEvents.AuthListener; 
import com.facebook.android.SessionEvents.LogoutListener; 
public class FBActivity extends Activity { 


    //public static final String APP_ID = "Here is my APP_ID"; 


    Handler mHandler; 
    Bundle bundle ; 
    Context context1; 
    private LoginButton mLoginButton; 
    private TextView mText; 
    // private Button mRequestButton; 
    private Button mPostButton; 
    String name; 
    private Facebook mFacebook; 
    Context context=getBaseContext(); 
    private static final int MESSAGEPUBLISHED = 2; 
    private AsyncFacebookRunner mAsyncRunner; 
    private String title1,desc1,imagurl1,fburl1; 
    private String spanish; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Bundle b=new Bundle(); 
     b=this.getIntent().getExtras(); 
     title1=b.getString("title"); 
     desc1=b.getString("desc"); 
     imagurl1=b.getString("imageurl"); 
     fburl1=b.getString("fb_url"); 
    // url = bundle.getString("URL"); 
     System.out.println("image url"+imagurl1); 
     mHandler = new Handler(); 
     if (APP_ID == null) { 
      Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + 
        "specified before running this example: see Example.java"); 
     } 

     setContentView(R.layout.main1); 
     mLoginButton = (LoginButton) findViewById(R.id.login); 
     mText = (TextView) FBActivity.this.findViewById(R.id.txt); 
     // mRequestButton = (Button) findViewById(R.id.requestButton); 
     mPostButton = (Button) findViewById(R.id.postButton); 
     Button back=(Button)findViewById(R.id.back); 
     back.setOnClickListener(new OnClickListener(){ 
      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       finish(); 
      }}); 
     mFacebook = new Facebook(APP_ID); 
     mAsyncRunner = new AsyncFacebookRunner(mFacebook); 

     SessionStore.restore(mFacebook, this); 
     SessionEvents.addAuthListener((AuthListener) new SampleAuthListener()); 
     SessionEvents.addLogoutListener((LogoutListener) new SampleLogoutListener()); 
     mLoginButton.init(this, mFacebook); 

    /* mRequestButton.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       mAsyncRunner.request("me", new SampleRequestListener()); 
       finish(); 
      } 


     });*/ 
     /* mRequestButton.setVisibility(mFacebook.isSessionValid() ? 
       View.VISIBLE : 
       View.INVISIBLE);*/ 

     mPostButton.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       Bundle myParams = new Bundle(); 
       myParams.putString("attachment", "{\"name\":\""+title1+"\"," +"\"href\":\""+fburl1+"\",\"" + 
         "caption\":\""+" "+"\",\"description\":\" " + "\",\"media\":[{\"type\":\"image\",\"src\":" + "\""+imagurl1+"\"," +"\"href\":\"http://developers.facebook.com/\"}]," + 
         "\"properties\":{\""+" "+"\":{\"text\":\"" + 
         " \",\"href\":\"http://www.facebook." + 
         "com\"}}}");; 
         // myParams.putString("attachment",attachment); 
       myParams.putString("message", ""); 
       mFacebook.dialog(FBActivity.this,"stream.publish",myParams, new SampleDialogListener()); 
      } 
     }); 
     mPostButton.setVisibility(mFacebook.isSessionValid() ? 
       View.VISIBLE : 
       View.INVISIBLE); 
    } 
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, 
            Intent data) { 
     mFacebook.authorizeCallback(requestCode, resultCode, data); 
    } 

    public class SampleAuthListener implements AuthListener { 

     public void onAuthSucceed() { 
      mText.setText("Successfully logged in! "); 
      // mRequestButton.setVisibility(View.VISIBLE); 
      mPostButton.setVisibility(View.VISIBLE); 
     } 

     public void onAuthFail(String error) { 
      mText.setText("Login Failed: " + error); 
     } 
    } 

    public class SampleLogoutListener implements LogoutListener { 
     public void onLogoutBegin() { 
      mText.setText("Logging out..."); 
     } 

     public void onLogoutFinish() { 
      mText.setText("You have logged out! "); 
      // mRequestButton.setVisibility(View.INVISIBLE); 
      mPostButton.setVisibility(View.INVISIBLE); 
     } 
    } 
    public class SampleRequestListener extends BaseRequestListener { 
     public void onComplete(final String response) { 
      try { 
       // process the response here: executed in background thread 
       JSONObject json = Util.parseJson(response); 
       // then post the processed result back to the UI thread 
       // if we do not do this, an runtime exception will be generated 
       // e.g. "CalledFromWrongThreadException: Only the original 
       // thread that created a view hierarchy can touch its views." 
       FBActivity.this.runOnUiThread(new Runnable() { 
        public void run() { 
         mText.setText("Hello there,"+ "!"); 
        } 
       }); 
      } catch (JSONException e) { 
       Log.w("Facebook-Example", "JSON Error in response"); 
      } catch (FacebookError e) { 
       Log.w("Facebook-Example", "Facebook Error: " + e.getMessage()); 
      } 
     } 
    } 
    public class SampleUploadListener extends BaseRequestListener { 

     public void onComplete(final String response) { 
      try { 
       // process the response here: (executed in background thread) 
       Log.d("Facebook-Example", "Response: " + response.toString()); 
       JSONObject json = Util.parseJson(response); 
       final String src = json.getString("src"); 

       // then post the processed result back to the UI thread 
       // if we do not do this, an runtime exception will be generated 
       // e.g. "CalledFromWrongThreadException: Only the original 
       // thread that created a view hierarchy can touch its views." 
       FBActivity.this.runOnUiThread(new Runnable() { 
        public void run() { 
         mText.setText("Hello there, photo has been uploaded at \n" + src); 
        } 
       }); 
      } catch (JSONException e) { 
       Log.w("Facebook-Example", "JSON Error in response"); 
      } catch (FacebookError e) { 
       Log.w("Facebook-Example", "Facebook Error: " + e.getMessage()); 
      } 
     } 
    } 
    public class WallPostRequestListener extends BaseRequestListener { 

     public void onComplete(final String response) { 
      Log.v("Facebook-Example", "Got response: " + response); 
      String message = "<empty>"; 
      String r=null; 
      try { 
       JSONObject json = Util.parseJson(response); 

       message = json.getString("message"); 

      } catch (JSONException e) { 
       Log.w("Facebook-Example", "JSON Error in response"); 
      } catch (FacebookError e) { 
       Log.w("Facebook-Example", "Facebook Error: " + e.getMessage()); 
      } 
      final String text = "Story posted successfully " ; 
      FBActivity.this.runOnUiThread(new Runnable() { 
       public void run() { 
        mText.setText(text); 

       } 
      }); 
     } 
    } 

    public class WallPostDeleteListener extends BaseRequestListener { 

     public void onComplete(final String response) { 
      if (response.equals("true")) { 
       Log.d("Facebook-Example", "Successfully deleted wall post"); 

       FBActivity.this.runOnUiThread(new Runnable() { 
        public void run() { 
         // mRequestButton.setVisibility(View.VISIBLE); 
        } 
       }); 

      } else { 
       Log.d("Facebook-Example", "Could not delete wall post"); 
      } 
     } 
    } 

    public class SampleDialogListener extends BaseDialogListener { 

     public void onComplete(Bundle values) { 
      final String postId = values.getString("post_id"); 
      if (postId != null) { 
       Log.d("Facebook-Example", "Dialog Success! post_id=" + postId); 
       mAsyncRunner.request(postId, new WallPostRequestListener()); 
      } else { 
       Log.d("Facebook-Example", "No wall post made"); 
      } 
     } 

     @Override 
     public void onError(DialogError e) { 
      // TODO Auto-generated method stub 

     } 
    } 

} 

答えて

関連する問題