55import android .os .Bundle ;
66import android .util .Log ;
77
8- import com .facebook .HttpMethod ;
9- import com .facebook .Request ;
10- import com .facebook .Response ;
11- import com .facebook .Session ;
12- import com .facebook .model .GraphUser ;
8+ import com .facebook .AccessToken ;
9+ import com .facebook .GraphRequest ;
10+ import com .facebook .GraphResponse ;
1311
1412import org .json .JSONArray ;
1513import org .json .JSONException ;
@@ -26,39 +24,46 @@ public class FacebookApi {
2624 public static final boolean INFO = ApplicationWrapper .LOG_INFO ;
2725 public static final String APP_ID = "903137443064438" ;
2826 private static final String TAG = "FacebookApi" ;
29- public static String USER_ID = "" ;
30- public static Bundle FbDataBundle = new Bundle ();
31- private static Session session ;
3227
33- public static void setSession (Session s ) {
34- session = s ;
35- }
28+ public static String PROFILE_URL = "" ;
29+ public static String COVER_URL = "" ;
3630
3731 public static void getFacebookData (final FbGotDataCallback fgdc ) {
38- Request .newMeRequest (session , new Request .GraphUserCallback () {
39- @ Override
40- public void onCompleted (GraphUser gu , Response response ) {
41- if (gu != null ) {
42- if (DEBUG ) Log .d (TAG , "json = " + response .getGraphObject ().getInnerJSONObject ().toString ());
43- JSONObject responseObject = response .getGraphObject ().getInnerJSONObject ();
44- USER_ID = gu .getId ();
45- try {
46- FbDataBundle .putString (ParseTables .Users .EMAIL , responseObject .getString ("email" ));
47- FbDataBundle .putString (ParseTables .Users .NAME , gu .getName ());
48- FbDataBundle .putString (ParseTables .Users .USERNAME , gu .getUsername ());
49- FbDataBundle .putString (ParseTables .Users .CITY , "" + gu .getLocation ().getLocation ().getCity ());
50- } catch (Exception e ) {
51- // e.printStackTrace();
32+
33+ final Bundle b = new Bundle ();
34+ GraphRequest request = GraphRequest .newMeRequest (
35+ AccessToken .getCurrentAccessToken (),
36+ new GraphRequest .GraphJSONObjectCallback () {
37+ @ Override
38+ public void onCompleted (
39+ JSONObject object ,
40+ GraphResponse response ) {
41+ if (DEBUG ) Log .d (TAG ,"" +object .toString ());
42+ try {
43+ if (!object .isNull ("cover" ))
44+ b .putString (ParseTables .Users .COVER ,object .getJSONObject ("cover" ).getString ("source" ));
45+ else
46+ b .putString (ParseTables .Users .COVER , "" );
47+ String id = object .getString ("id" );
48+ b .putString (ParseTables .Users .IMAGE ,"https://graph.facebook.com/" + id + "/picture??width=300&&height=300" );
49+ b .putString (ParseTables .Users .NAME , object .getString ("name" ));
50+ b .putString (ParseTables .Users .EMAIL , object .getString ("email" ));
51+
52+ fgdc .gotData (b );
53+ } catch (JSONException e1 ) {
54+ e1 .printStackTrace ();
55+ }
5256 }
53- FbDataBundle . putString ( ParseTables . Users . DOB , gu . getBirthday () );
54- fgdc . gotData ( FbDataBundle );
55- }
56- }
57- }) .executeAsync ();
57+ } );
58+ Bundle parameters = new Bundle ( );
59+ parameters . putString ( "fields" , "name,id,cover,email,birthday" );
60+ request . setParameters ( parameters );
61+ request .executeAsync ();
5862 return ;
5963 }
6064
6165 public static void getFacebookUserEvents (final FbGotEventDataCallback fgedc ) {
66+ /*
6267 Bundle bundle = new Bundle();
6368 bundle.putString("fields", "description,start_time,owner,name,cover");
6469 Request r = new Request(session, "/me/events", bundle,
@@ -73,58 +78,7 @@ public void onCompleted(Response response) {
7378 }
7479 }
7580 });
76- r .executeAsync ();
77- }
78-
79- public static void getProfilePicture (final FbGotProfilePictureCallback listener ) {
80- if (DEBUG ) Log .d (TAG , "getting profile picture" );
81- Bundle bundle = new Bundle ();
82- bundle .putString ("fields" , "picture" );
83- new Request (session , "me" , bundle ,
84- HttpMethod .GET , new Request .Callback () {
85- @ Override
86- public void onCompleted (final Response response ) {
87- new AsyncTask <Void , Void , Void >() {
88- @ Override
89- protected Void doInBackground (Void ... params ) {
90- try {
91- String objectId = response .getGraphObject ().getInnerJSONObject ().getString ("id" );
92- String sUrl = "https://graph.facebook.com/" + objectId + "/picture??width=300&&height=300" ;
93- Bitmap bitmap = Utilities .downloadBitmap (sUrl );
94- listener .gotProfilePicture (bitmap );
95- } catch (JSONException e ) {
96- e .printStackTrace ();
97- }
98- return null ;
99- }
100- }.execute ();
101- }
102- }).executeAsync ();
103- }
104-
105- public static void getCoverPicture (final FbGotCoverPictureCallback listener ) {
106- if (DEBUG ) Log .d (TAG , "getting cover picture" );
107- Bundle bundle = new Bundle ();
108- bundle .putString ("fields" , "cover" );
109- new Request (session , "me" , bundle ,
110- HttpMethod .GET , new Request .Callback () {
111- @ Override
112- public void onCompleted (final Response response ) {
113- new AsyncTask <Void , Void , Void >() {
114- @ Override
115- protected Void doInBackground (Void ... params ) {
116- try {
117- String sUrl = response .getGraphObject ().getInnerJSONObject ().getJSONObject ("cover" ).getString ("source" );
118- Bitmap bitmap = Utilities .downloadBitmap (sUrl );
119- listener .gotCoverPicture (bitmap );
120- } catch (JSONException e ) {
121- e .printStackTrace ();
122- }
123- return null ;
124- }
125- }.execute ();
126- }
127- }).executeAsync ();
81+ r.executeAsync();*/
12882 }
12983
13084 public interface FbGotDataCallback {
0 commit comments