Pull facebook profile image to a panel

0
package com.didasko.eduardo.tender;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.facebook.AccessToken;
import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.HttpMethod;
import com.squareup.picasso.Picasso;
import org.json.JSONObject;

import de.hdodenhof.circleimageview.CircleImageView;
import static com.didasko.eduardo.tender.R.id.profile_pic;

public class TelaPerfil extends AppCompatActivity {


    Button btnSair;
    ImageView adReceita;
    ImageView verMreceitas;


    ImageView user_picture;

    JSONObject response, profile_pic_data, profile_pic_url;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tela_perfil);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        FacebookSdk.sdkInitialize(getApplicationContext());





        btnSair = (Button) findViewById(R.id.btnSair);
        btnSair.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(TelaPerfil.this, MainActivity.class);
                startActivity(intent1);
                finish();
            }
        });

        adReceita = (ImageView) findViewById(R.id.adReceita);
        adReceita.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(TelaPerfil.this, NovaReceita.class);
                startActivity(intent1);
                finish();
            }
        });

        verMreceitas = (ImageView) findViewById(R.id.verMreceitas);
        verMreceitas.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(TelaPerfil.this, MinhasReceitas.class);
                startActivity(intent1);
                finish();
            }
        });



        new GraphRequest(
                AccessToken.getCurrentAccessToken(),
                "/{user-id}/picture",
                null,
                HttpMethod.GET,
                new GraphRequest.Callback() {
                    public void onCompleted(GraphResponse response) {

                        user_picture = (CircleImageView)findViewById(profile_pic);

                    }
                }
        ).executeAsync();


        final Intent intent = getIntent();
        String jsondata = intent.getStringExtra("jsondata");

        setUserProfile(jsondata);


        TextView user_name = (TextView)findViewById(R.id.nome);
        user_name.setText(Prefs.getNome(this));



    }

    public  void  setUserProfile(String jsondata){

        try {
            response = new JSONObject(jsondata);
            profile_pic_data = new JSONObject(response.get("picture").toString());
            profile_pic_url = new JSONObject(profile_pic_data.getString("data"));

            Picasso.with(this).load(profile_pic_url.getString("url"))
                    .into(user_picture);
        } catch (Exception e){
            e.printStackTrace();
        }

    }



}

I'm using the Graph Request method, but it's not pulling the profile image, the name it pulls, since the image is still in the same blank, am I doing something wrong? Is something missing?

OBS: This is not my main activity, it is a page that I want to display the name and image of the facebook user profile.

    
asked by anonymous 13.02.2017 / 20:18

0 answers