2013-10-23 72 views
0

我正在寫一個日曆應用程序,其中,我將所有我的Facebook朋友的名單與他們的姓名,出生日期和個人資料圖片提取到我的日曆中。我怎麼能得到所有這些。請幫幫我。同步Facebook朋友生日與我的Android應用程序

+0

你到目前爲止嘗試過什麼?你有做過什麼研究嗎?你有什麼想法? – Manuel

+0

到現在爲止我開發的日曆,現在我試圖添加Facebook朋友b'days到日曆(與facebook同步)。所以你可以請提供一些信息如何與fb同步,並給我一些鏈接,以獲得它的想法。感謝 – Ramakrishna

回答

0

首先創建對象和veriable爲Facebook:

private static String FACEBOOK_APP_ID = "492429660800628"; 
private Facebook facebook; 
private AsyncFacebookRunner mAsyncRunner; 

後onCreate方法:使用最新的Facebook的Android SDK

public void getProfileInformation() { 


    try { 

     JSONObject profile = Util.parseJson(facebook.request("me")); 
     Log.e("Profile", "" + profile); 

     mUserId = profile.getString("id"); 
     mUserToken = facebook.getAccessToken(); 
     mUserName = profile.getString("name"); 
     mUserEmail = profile.getString("email"); 

     runOnUiThread(new Runnable() { 

      public void run() { 

       Log.e("FaceBook_Profile",""+mUserId+"\n"+mUserToken+"\n"+mUserName+"\n"+mUserEmail); 

       Toast.makeText(getApplicationContext(), 
         "Name: " + mUserName + "\nEmail: " + mUserEmail, 
         Toast.LENGTH_LONG).show(); 



      } 

     }); 

    } catch (FacebookError e) { 

     e.printStackTrace(); 
    } catch (MalformedURLException e) { 

     e.printStackTrace(); 
    } catch (JSONException e) { 

     e.printStackTrace(); 
    } catch (IOException e) { 

     e.printStackTrace(); 
    } 

} 

protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.login_screen); 

    facebook = new Facebook(FACEBOOK_APP_ID); 
    mAsyncRunner = new AsyncFacebookRunner(facebook); 

    loginFacebook();//this method when called when you required.. 

} 



private void loginFacebook() { 

    if (!facebook.isSessionValid()) { 

     facebook.authorize(this, new String[] { "email", "publish_stream", 
       "read_stream" }, new LoginDialogListener()); 

    } else { 

     getProfileInformation(); 

    } 

} 



class LoginDialogListener implements DialogListener { 

    public void onComplete(Bundle values) { 
     try { 

      getProfileInformation(); 

     } catch (Exception error) { 
      Toast.makeText(LoginActivity.this, error.toString(), 
        Toast.LENGTH_SHORT).show(); 
     } 
    } 

    public void onFacebookError(FacebookError error) { 
     Toast.makeText(LoginActivity.this, 
       "Something went wrong. Please try again.", 
       Toast.LENGTH_LONG).show(); 
    } 

    public void onError(DialogError error) { 
     Toast.makeText(LoginActivity.this, 
       "Something went wrong. Please try again.", 
       Toast.LENGTH_LONG).show(); 
    } 

    public void onCancel() { 
     Toast.makeText(LoginActivity.this, 
       "Something went wrong. Please try again.", 
       Toast.LENGTH_LONG).show(); 
    } 
} 

請嘗試登錄博客後,這個方法 from​​https://developers.facebook.com/docs/android/fetch-user-data/

+0

+1好評如果有適當的補充... – Jitendra

+0

如何在我的應用程序編碼中使用Facebook json數據。 ? 從哪個網址我們可以訪問json數據。? – Ramakrishna

+0

只能使用此代碼訪問用戶數據 –

相關問題