2016-06-24 7 views
0

Facebook SDKを統合した後、近くのイベントを表示する方法は、AndroidのFacebookログインを意味しますか? FacebookのSDKとの統合のコールバックメソッドのonsuccessFacebook SDKを統合した後、近くのイベントを表示するAndroidのFacebookログインを意味しますか?

AccessToken tok; 
tok = AccessToken.getCurrentAccessToken(); 
// login_button.setReadPermissions(Arrays.asList("user_location", "user_birthday", "user_likes", "user_events", "read_stream")); 

String id = tok.getUserId(); 
// String id=getResources().getString(R.string.facebook_app_id); 
Log.d("--id", id); 

new GraphRequest(
    AccessToken.getCurrentAccessToken(), "/"+id+"/events", null, HttpMethod.GET, 
    new GraphRequest.Callback() { 
     public void onCompleted(GraphResponse response) { 

      /* handle the result */ 
      Log.e("--result", response + ""); 

     } 
    } 
).executeAsync(); 

は、私はこのコードを書かれています。

しかし、それは見せている:

result: {Response: responseCode: 200, graphObject: {"data":[]}, error: null}

答えて

0
package com.example.neelu.chatapp; 

import android.content.Intent; 
import android.content.pm.PackageInfo; 
import android.content.pm.PackageManager; 
import android.content.pm.Signature; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Base64; 
import android.util.Log; 
import android.view.Menu; 
import android.view.MenuItem; 

import com.facebook.AccessToken; 
import com.facebook.CallbackManager; 
import com.facebook.FacebookCallback; 
import com.facebook.FacebookException; 
import com.facebook.FacebookSdk; 
import com.facebook.GraphRequest; 
import com.facebook.GraphResponse; 
import com.facebook.HttpMethod; 
import com.facebook.Profile; 
import com.facebook.appevents.AppEventsLogger; 
import com.facebook.login.LoginResult; 
import com.facebook.login.widget.LoginButton; 

import java.security.MessageDigest; 
import java.security.NoSuchAlgorithmException; 
import java.util.Arrays; 

public class MainActivity extends AppCompatActivity { 

    CallbackManager callbackManager; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     facebookSDKInitialize(); 
     setContentView(R.layout.activity_main); 

     LoginButton loginButton = (LoginButton) findViewById(R.id.login_button); 
     loginButton.setReadPermissions("email"); 
     getLoginDetails(loginButton); 
     getHashKey(); 
    } 


    public void getHashKey() { 
     try { 

      PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 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 (PackageManager.NameNotFoundException e) { 
      Log.e("name not found", e.toString()); 
     } catch (NoSuchAlgorithmException e) { 
      Log.e("no such an algorithm", e.toString()); 
     } 
    } 


    protected void facebookSDKInitialize() { 

     FacebookSdk.sdkInitialize(getApplicationContext()); 
     callbackManager = CallbackManager.Factory.create(); 
    } 

    protected void getLoginDetails(final LoginButton login_button) { 

     // Callback registration 
     login_button.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
      @Override 
      public void onSuccess(LoginResult login_result) { 
//    Intent intent = new Intent(MainActivity.this,HomePage.class); 
//    startActivity(intent); 
//    AccessToken accessToken= login_result.getAccessToken(); 
//    Profile profile= Profile.getCurrentProfile(); 
//    if(profile!=null) 
//    { 
////     textViewMessage.setText("welcome"+ profile.getName()); 
//    } 

       AccessToken tok; 
       tok = AccessToken.getCurrentAccessToken(); 
//    login_button.setReadPermissions(Arrays.asList("user_location", "user_birthday", "user_likes", "user_events", "read_stream")); 

       String id = tok.getUserId(); 
//    String id=getResources().getString(R.string.facebook_app_id); 
       Log.d("--id", id); 
       new GraphRequest(
         AccessToken.getCurrentAccessToken(), "/"+id+"/events", null, HttpMethod.GET, 
         new GraphRequest.Callback() { 
          public void onCompleted(GraphResponse response) { 
      /* handle the result */ 

           Log.e("--result", response + ""); 
          } 
         } 
       ).executeAsync(); 

      } 

      @Override 
      public void onCancel() { 
       // code for cancellation 
      } 

      @Override 
      public void onError(FacebookException exception) { 
       // code to handle error 
      } 
     }); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     callbackManager.onActivityResult(requestCode, resultCode, data); 
     Log.e("data", data.toString()); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     // getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 

     return super.onOptionsItemSelected(item); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 

     // Logs 'install' and 'app activate' App Events. 
     AppEventsLogger.activateApp(this); 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 

     // Logs 'app deactivate' App Event. 
     AppEventsLogger.deactivateApp(this); 
    } 

} 
+0

をアンドロイドFacebookとの統合SDKの事象により近い示すことによって、私を助けてください???/?? –

関連する問題