Skip to content

Instantly share code, notes, and snippets.

View ziginsider's full-sized avatar
🤴
καὶ σύ, τέκνον

Aliaksei ziginsider

🤴
καὶ σύ, τέκνον
View GitHub Profile
mavenCentral()
<string name="facebook_app_id">383374132098267</string>
<string name="facebook_login_protocol_scheme">fb383374132098267</string>
public class MainActivity extends AppCompatActivity {
CallbackManager callbackManager;
TextView txtEmail, txtBirthday, txtFriends, txtLocation;
ProgressDialog mDialog;
ImageView imgAvatar;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//printKeyHash();
callbackManager = CallbackManager.Factory.create();
txtBirthday = (TextView) findViewById(R.id.txt_birthday);
@Override
public void onSuccess(LoginResult loginResult) {
mDialog = new ProgressDialog(MainActivity.this);
mDialog.setMessage("Retrieving data...");
mDialog.show();
String accessToken = loginResult.getAccessToken().getToken();
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
private void getData(JSONObject object) {
try {
URL profile_picture
= new URL("https://graph.facebook.com/"
+ object.getString("id")
+ "/picture?width=250&height=250");
Picasso.with(this).load(profile_picture.toString()).into(imgAvatar);
txtEmail.setText(object.getString("email"));
...
// If already login
if (AccessToken.getCurrentAccessToken() != null) {
//Just set User ID
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
getData(object);
}
<data android:scheme="@string/facebook_login_protocol_scheme" />
{
"id":"1336398453137452",
"email":"[email protected]",
"location":
{
"id":"107677462599905",
"name":"Minsk, Belarus"
},
"birthday":"04\/13\/1986",
"friends":
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout ...
<LinearLayout ...
<Button
android:id="@+id/share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Share content" />