- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 twitter 文档来关注使用以下 url https://dev.twitter.com/rest/reference/post/friendships/create 的用户
使用 API 时 https://api.twitter.com/1.1/friendships/create.json?user_id=1401881&follow=true ,我收到 403 错误,
调用api的代码如下。
public String getTwitterFollow(String url) {
//?screen_name=MDforLives&follow=true
String results = null;
// Step 1: Encode consumer key and secret
try {
// URL encode the consumer key and secret
String urlApiKey = URLEncoder.encode(CONSUMER_KEY, "UTF-8");
String urlApiSecret = URLEncoder.encode(CONSUMER_SECRET, "UTF-8");
// Concatenate the encoded consumer key, a colon character, and the
// encoded consumer secret
String combined = urlApiKey + ":" + urlApiSecret;
// Base64 encode the string
String base64Encoded = Base64.encodeToString(combined.getBytes(), Base64.NO_WRAP);
// Step 2: Obtain a bearer token
HttpPost httpPost = new HttpPost(TwitterTokenURL);
httpPost.setHeader("Authorization", "Basic " + base64Encoded);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
httpPost.setEntity(new StringEntity("grant_type=client_credentials"));
String rawAuthorization = getResponseBody(httpPost);
Authenticated auth = jsonToAuthenticated(rawAuthorization);
// Applications should verify that the value associated with the
// token_type key of the returned object is bearer
if (auth != null && auth.token_type.equals("bearer")) {
url = url.replaceAll(" ", "%20");
// Step 3: Authenticate API requests with bearer token
HttpPost httpGet = new HttpPost(url);
// construct a normal HTTPS request and include an Authorization
// header with the value of Bearer <>
httpGet.setHeader("Authorization", "Bearer " + auth.access_token);
// httpGet.setHeader("Content-Type", "application/json");
StringEntity stringEntity;
JSONObject obj=new JSONObject();
obj.put("screen_name","MDforLives");
obj.put("follow","true");
stringEntity = new StringEntity(obj.toString());
stringEntity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
// httpGet.setEntity(stringEntity);
// update the results with the body of the response
results = getResponseBody(httpGet);
System.out.println("results returns" + results);
}
} catch (Exception ex) {
}
return results;
}
所以请建议 url 有什么问题,或者 android 端是否有任何代码问题。
最佳答案
来自 official docs :
If you are already friends with the user a HTTP 403 may be returned, though for performance reasons you may get a 200 OK message even if the friendship already exists.
这种行为可能是正常的;)
关于android - Twitter friendships/create 给出 403/Forbidden 错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40102768/
我发布了这个问题,这是对我的另一个问题的总结 question . 我有 两个数据库 : 1) db_users。 2) db_friends。 我强调它们存储在 单独的数据库 在不同的服务器上,因此
Before you show me duplicates, please note that I've searched through the site an have found some ex
这个问题在这里已经有了答案: Why does C++ not allow inherited friendship? (9 个回答) 关闭 9 年前。 一共有三个类: class A {
我猜那些在社区和社交网络中工作过的人可能在这方面有一些经验。 我正在尝试绘制我网站上存在的所有友谊的图表,并以此确定相互关联的用户群。 有没有人有做这样的事情的经验?此外,SQL Server 200
我正在关注 http://railscasts.com/episodes/163-self-referential-association做一个友谊系统。 #Friendship model id |
Facebook 的“See Friendship”选项显示了两个用户在彼此的墙上发帖的完整历史记录。我相信此功能以前称为“墙到墙”。有没有办法以编程方式(通过 PHP)生成此提要?我可以构建一个 P
我需要有关 MySQL 查询的帮助。查询的输出应如下所示 User1 User2 xxx1 xxx2 xxx3 xxx1 但不是 User1 Use
这是这个问题的延续: Original Question (SO) 这个问题的答案涉及以下一组模型: class User :friendships #... end class Friendshi
我最近看到许多文章指出要为 NoSQL 数据库扁平化数据。来自传统的 SQL 数据库,我意识到我正在 GAE 中复制 SQL 数据库行为。所以我开始尽可能地重构代码。 我们有一个社交媒体网站,用户可以
我正在使用 twitter 文档来关注使用以下 url https://dev.twitter.com/rest/reference/post/friendships/create 的用户 使用 AP
我想为 Android 开发一个社交网络应用程序,用户可以在其中发送和接受好友请求。我已经做到了。用户可以像这样向其他人发送请求: 用户表(用户) id
我通过构建应用程序来学习 Rails。在我将此代码添加到我的 users_controller.rb 之前,我的应用程序运行良好 def show @user = User.find(para
我在这里看过关于 self 参照关系的 railscast:http://railscasts.com/episodes/163-self-referential-association 我在此基础上
我正在尝试构建一个拥有用户和友谊的应用程序。我正在使用 Rails 5、Ruby 2.4.0 和 PostgreSQL 9.5.6 我目前正在尝试实现添加好友功能。我为友谊和 friend (通过友谊
我是一名优秀的程序员,十分优秀!