2012-01-10 14 views
1

私はアンドロイドモバイルとFacebookを統合しようとしています。私のアプリケーションからテキストを取り込んでFacebookのステータスとして入れたいのですが、私は見たときにfacebook_sdkを試しました私はいくつかの詳細をいただければ幸いですAndroidでのFacebook認証の問題

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    button1 = (Button)findViewById(R.id.Button1); 
    button2 = (Button)findViewById(R.id.Button2); 
    tv1 = (TextView)findViewById(R.id.TextView1); 
    et1 = (EditText)findViewById(R.id.EditText1); 
    button1.setOnClickListener(new OnClickListener(){ 
     @Override 
     public void onClick(View v) { 
      b1Click(); 
     } 

    }); 
    button2.setOnClickListener(new OnClickListener(){ 
     @Override 
     public void onClick(View v) { 
      b2Click(); 
     } 

    }); 
} 
private void saveFBToken(String token, long tokenExpires){ 
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 
    prefs.edit().putString("FacebookToken", token).commit(); 
} 

private void fbAuthAndPost(final String message){ 

    facebook.authorize(this, new String[]{"publish_stream"},new DialogListener() { 

     @Override 
     public void onComplete(Bundle values) { 
      Log.d(this.getClass().getName(),"Facebook.authorize Complete: "); 
      saveFBToken(facebook.getAccessToken(), facebook.getAccessExpires()); 
      updateStatus(values.getString(Facebook.TOKEN), message); 
     } 

     @Override 
     public void onFacebookError(FacebookError error) { 
      Log.d(this.getClass().getName(),"Facebook.authorize Error: "+error.toString()); 
     } 

     @Override 
     public void onError(DialogError e) { 
      Log.d(this.getClass().getName(),"Facebook.authorize DialogError: "+e.toString()); 
     } 

     @Override 
     public void onCancel() { 
      Log.d(this.getClass().getName(),"Facebook authorization canceled"); 
     } 
    }); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode,Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch (requestCode){ 
    case Facebook.FORCE_DIALOG_AUTH: 
     facebook.authorizeCallback(requestCode, resultCode, data); 
    } 
} 

private void b1Click(){ 

    mAuthAttempts = 0; 

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 
    mFacebookToken = prefs.getString("FacebookToken", ""); 

    if(mFacebookToken.equals("")){ 
     fbAuthAndPost(et1.getText().toString()); 
    }else{ 
     updateStatus(mFacebookToken,et1.getText().toString()); 
    } 
} 

private void b2Click(){ 
    mAuthAttempts = 0; 
    updateStatus(facebook.TOKEN,et1.getText().toString()); 
} 

public void updateStatus(String accessToken, String message){ 
    try {   
     Bundle bundle = new Bundle(); 
     bundle.putString("message", message);   
     bundle.putString(Facebook.TOKEN,accessToken);   
     String response = facebook.request("me/feed",bundle,"POST");   
     Log.d("UPDATE RESPONSE",""+response); 
     showToast("Update process complete. Respose:"+response); 
     if(response.indexOf("OAuthException") > -1){ 
      if(mAuthAttempts==0){ 
       mAuthAttempts++; 
       fbAuthAndPost(message); 
      }else{ 
       showToast("OAuthException:"); 
      } 
     } 
    } catch (MalformedURLException e) {   
     Log.e("MALFORMED URL",""+e.getMessage()); 
     showToast("MalformedURLException:"+e.getMessage()); 
    } catch (IOException e) {   
     Log.e("IOEX",""+e.getMessage()); 
     showToast("IOException:"+e.getMessage()); 
    } 

    String s = facebook.getAccessToken()+"\n"; 
    s += String.valueOf(facebook.getAccessExpires())+"\n"; 
    s += "Now:"+String.valueOf(System.currentTimeMillis())+"\n"; 
    tv1.setText(s); 
} 
private void showToast(String message){ 
    Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show(); 
} 
+0

logcat ...を入力すると、エラーの詳細が表示されます。 –

+0

あなたのFacebookの問題を解決することができますあなたのFacebookのAPIのクラスを入れてください.. –

+0

致命的な例外:メイン android.content.res.Resources $ NotFoundException:リソースID#0x7f020005 –

答えて

0

事前に ありがとう:menifestで完全なインターネット接続がありますが、デバッグモードでは、アプリケーションは、ラインfacebook.authorize()で終端されています...以下の私のコードですアプリがクラッシュする前に受け取ったエラーUsamaのように、logcatは素晴らしいと言いました。変数facebook = new Facebook(APP_ID);をどこで初期化するか分かりません。あなたのマニフェストに使用しているすべてのアクティビティがあることを確認してください。最後に、私はあなたにこれを教えてくれます: https://github.com/facebook/facebook-android-sdk/blob/master/examples/simple/src/com/facebook/android/Example.java

私はこれが役立つことを願っています。

< < Facebookページにログインしようとすると、ユーザーとパスワードが正しい場合、トークンを受け取ります。これは、アプリケーションに有効なユーザーがログインしていることを意味します。 SessionStoreクラスは、そのトークンを共有プリファレンスに保存します。それで、トークンを使って、後でパスワードを尋ねることなく、Facebookに再び接続することができます。セッションが期限切れになっていない場合にのみ、これを行うことができます。 エラーについて: "この例外は、要求されたリソースが見つからない場合、リソースAPIによってスローされます。

私はずっと前にFacebookのインテグレーションをしていましたが、会社のために私はそれを持っていないのでコードを渡すことはできません。おそらくそれを助けるかもしれないこのポストを見てください。 http://www.jiahaoliuliu.com/2011/05/android-runtime-error.html

もっと明白なものがあるかどうかを見て回ります。

+0

私はSessionStoreクラスを理解していないfacebook_sdk.jarには存在しません。私は使用しています。 –

+0

致命的な例外:メイン android.content.res.Resources $ NotFoundException:リソースID#0x7f020005 –

0
android.content.res.Resources$NotFoundException 

がアイディアでプロジェクトをインポートするときに上書きされることがあります。