Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 图形Facebook赢得';无法检索数据_Android_Facebook_Android Studio_Facebook Graph Api - Fatal编程技术网

Android 图形Facebook赢得';无法检索数据

Android 图形Facebook赢得';无法检索数据,android,facebook,android-studio,facebook-graph-api,Android,Facebook,Android Studio,Facebook Graph Api,我正在尝试使用graph Facebook从Facebook检索数据,如个人资料图片、性别、年龄、姓名、ID和链接,我仅成功获取Facebook个人资料图片,但其他图片无法检索。请帮忙 MainActivity.java pictureAsync.java 这是一项不推荐使用的功能。@Martijn Pieters向我展示重复的问题,为什么它标记为重复。您对多个问题发布了相同的答案;你认为你对自己问题的回答也回答了另一个问题,所以很明显你觉得你自己的答案适用于这两个问题。我现在知道你的答案太单薄

我正在尝试使用graph Facebook从Facebook检索数据,如
个人资料图片、性别、年龄、姓名、ID和链接
,我仅成功获取
Facebook个人资料图片
,但其他图片无法检索。请帮忙

MainActivity.java

pictureAsync.java


这是一项不推荐使用的功能。

@Martijn Pieters向我展示重复的问题,为什么它标记为重复。您对多个问题发布了相同的答案;你认为你对自己问题的回答也回答了另一个问题,所以很明显你觉得你自己的答案适用于这两个问题。我现在知道你的答案太单薄了,无法支持这个结论,我重新打开了这个。以后,如果你能把你的答案写得更详细一些,那会很有帮助;比如什么版本的东西是不推荐的。
package com.example.facebookprofile;

import org.json.JSONException;
import org.json.JSONObject;
import com.example.facebookprofile.pictureAsync.onImageDownloaded;
import com.example.facebookprofile.profileAsync.profileImplement;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements profileImplement, onImageDownloaded {

    ProgressDialog dialog;

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void onClick(View view){
        EditText enterUsername = (EditText) findViewById(R.id.enterUsername);
        String s = "https://graph.facebook.com/" + enterUsername.getEditableText().toString();
        pictureAsync picTask = new pictureAsync(this);
        profileAsync task = new profileAsync(this);
        picTask.execute(s + "/picture?type=large");
        picTask.delegate = this;
        task.delegate = this;
        task.execute(s);


    }

    public static User parseJSON(String jsonString) throws JSONException{
        JSONObject top = new JSONObject(jsonString);
        String name = "NA";
        if(top.has("name"))
        name = top.getString("name");
        String username = top.getString("username");
        String id = "NA";
        if(top.has("id"))
        id = top.getString("id");
        String gender = "NA";
        if(top.has("gender"))
        gender = top.getString("gender");
        String link = "https://www.facebook.com/"+username;
        if(top.has("link"))
        link = top.getString("link");
        User output = new User(name, username, id, gender, link);
        return output;
    }

    @Override
    public void update(User user) {
        // TODO Auto-generated method stub
        if(user == null){
            Toast t = Toast.makeText(this, "Invalid username", Toast.LENGTH_SHORT);
            t.show();
        }
        else{
            TextView name = (TextView) findViewById(R.id.name);
            TextView id = (TextView) findViewById(R.id.id);
            TextView gender = (TextView) findViewById(R.id.gender);
            TextView link = (TextView) findViewById(R.id.link);
            name.setText(user.name);
            id.setText(user.id);
            gender.setText(user.gender);
            link.setText(user.link);
        }
    }

    @Override
    public void setImage(Bitmap bitmap) {
        // TODO Auto-generated method stub
        if(bitmap != null){
            ImageView image = (ImageView) findViewById(R.id.imageView1);
            image.setImageBitmap(bitmap);
        }
    }
}
package com.example.facebookprofile;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;

public class pictureAsync extends AsyncTask<String, Integer, Bitmap> {

    Context context;
    onImageDownloaded delegate;

    public interface onImageDownloaded{
        public void setImage(Bitmap bitmap);
    }
    public pictureAsync(Context context) {
        this.context = context;
    }
    @Override
    protected Bitmap doInBackground(String... params) {
        String picUrl = params[0];
        try {
            URL url = new URL(picUrl);
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    @Override
    protected void onPostExecute(Bitmap result) {
        super.onPostExecute(result);
        if(delegate!=null)
        delegate.setImage(result);
    }
}
package com.example.facebookprofile;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONException;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;    

public class profileAsync extends AsyncTask<String, Integer, User> {

    profileImplement delegate;
    Context context;
    ProgressDialog dialog;


    public profileAsync(Context context) {
        this.context = context;
    }
    @Override
    public void onPreExecute() {
        super.onPreExecute();
        dialog = new ProgressDialog(context);
        dialog.setMessage("Loading...Please wait");
        dialog.show();
    }

    public interface profileImplement{
        public void update(User user);
    }

    @Override

    protected User doInBackground(String... arg) {
        String user = arg[0];
        try {
            URL url = new URL(user);
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            InputStream input = connection.getInputStream();
            if(input == null) return null;
            Scanner networkScanner = new Scanner(input);
            StringBuffer buffer = new StringBuffer();
            int count = 0;
            while(networkScanner.hasNext()){
                String line = networkScanner.next();
                count += line.length();
                //publishProgress(count);
                buffer.append(line);
            }
            networkScanner.close();
            return MainActivity.parseJSON(buffer.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(User result) {
        dialog.dismiss();
        if(delegate != null)
        delegate.update(result);
    }

//  protected void onProgressUpdate(Integer... values) {
//      // TODO Auto-generated method stub
//      super.onProgressUpdate(values);
//      dialog.setMessage("downloaded: " + values[0]);
//  }
}
package com.example.facebookprofile;

public class User {
    String name;
    String username;
    String id;
    String gender;
    String link;

    User(String name, String username , String id , String gender , String link){
        this.name = name;
        this.username = username;
        this.id = id;
        this.gender = gender;
        this.link = link;
    }
}