gpt4 book ai didi

android - 无法将 Facebook 页面的提要添加到我的应用程序中

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:33:59 25 4
gpt4 key购买 nike

我希望我的应用只显示 Facebook 页面发布的帖子,无需任何身份验证。这是代码:

public class Main extends Activity {

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

try {
String APP_ID = "1234567890";
String APP_SECRET = "1a2b3c4defghijk";
String OWNER_OF_FEED = "somepage";

HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(
"https://graph.facebook.com/oauth/access_token?client_id="+
APP_ID +
"&client_secret="+APP_SECRET+"&grant_type=client_credentials");

ResponseHandler<String> responseHandler = new BasicResponseHandler();

String access_token = client.execute(get, responseHandler);

String uri = "https://graph.facebook.com/" + OWNER_OF_FEED + "/feed?"
+ access_token;

get = new HttpGet(uri);
String responseBody = client.execute(get, responseHandler);

// responseBody contains JSON-encoded feed

//textview.setText(responseBody);
TextView txtv = (TextView) findViewById(R.id.feed);
txtv.setText(String.valueOf(responseBody));
}

catch (Exception ex) {
ex.printStackTrace();
}
}

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

但我无法在应用程序上获取任何内容。我在 list 文件中包含了互联网访问权限。

新代码:

public class MainActivity extends Activity {

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

URL url;
try {
url = new URL("https://www.facebook.com/feeds/page.php?format=rss20&id=289781571139242");

HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();

InputStream in = urlConnection.getInputStream();

InputStreamReader isw = new InputStreamReader(in);

int data = isw.read();
while (data != -1) {
char current = (char) data;
data = isw.read();
System.out.print(current);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

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

}

最佳答案

实际上有一种方法可以在未经用户许可的情况下获取页面公共(public)提要!

解决方案

  1. 获取页面Facebook Profile Id:最简单的方法是查询Graph API http://graph.facebook.com/ {你的页面用户名}。 例如适用于 oStream Android 应用 https://graph.facebook.com/oStreamApp将返回 Facebook 个人资料 ID 289781571139242

  2. 请求 Facebook 页面提要的 RSS:向 https://www.facebook.com/feeds/page.php?format=rss20&id= 发出 http 请求{yourAppId} 例如对于 oStream Android App 公开 https://www.facebook.com/feeds/page.php?format=rss20&id=289781571139242

Android 实现 将只是:

  1. http://graph.facebook.com/ 发出 http 请求{你的页面用户名}
  2. 解析内容并获取 YourPageId
  3. https://www.facebook.com/feeds/page.php?format=rss20&id= 发出 http 请求{你的AppId}
  4. 解析内容
  5. 根据需要显示内容

旁注这个问题与 Android 无关,只是与 Facebook API 有关。

关于android - 无法将 Facebook 页面的提要添加到我的应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15138860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com