- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
继续获取:
V/RESPONSE(13605): {
V/RESPONSE(13605): "error": {
V/RESPONSE(13605): "errors": [
V/RESPONSE(13605): {
V/RESPONSE(13605): "domain": "global",
V/RESPONSE(13605): "reason": "parseError",
V/RESPONSE(13605): "message": "This API does not support parsing form-encoded input."
V/RESPONSE(13605): }
V/RESPONSE(13605): ],
V/RESPONSE(13605): "code": 400,
V/RESPONSE(13605): "message": "This API does not support parsing form-encoded input."
V/RESPONSE(13605): }
V/RESPONSE(13605): }
使用此代码:
String apiKey = "blahblahblah";
String address="https://www.googleapis.com/urlshortener/v1/url";
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(address);
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("key", apiKey));
pairs.add(new BasicNameValuePair("longUrl", original));
try {
post.setEntity(new UrlEncodedFormEntity(pairs));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
org.apache.http.HttpResponse response = client.execute(post);
String responseBody = EntityUtils.toString(response.getEntity());
Log.v("RESPONSE"," "+responseBody);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
tinyUrl="Protocol Error";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
tinyUrl="IO Error";
}
我不确定如何格式化它。有什么想法吗?
我尝试删除 UrlEncodedFormEntity
,但这当然行不通。
最佳答案
您需要将数据作为 json 发送,而不是像您尝试的那样以编码形式发送。
查看文档 here .
像这样将实体更改为 StringEntity:
post.setEntity(new StringEntity("{\"longUrl\": \"http://www.google.com/\"}"));
同时设置请求的内容类型:
post.setHeader("Content-Type", "application/json");
关于android - 从 Android 发布到 goo.gl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6052156/
在 C 编程中,我们如何初始化这个 int *goo,其中 goo 是图的边列表? 最佳答案 一维整数数组通常不能用于直观地存储图形,即没有某种映射代码。 至少有两种常见的方法可以用数学方式表示矩阵/
如果我猜对了,GOOS在编译源代码时确定。 为了更好地支持多个操作系统,我对 GOOS 感兴趣可能。 当然,它可能有无限的可能性,因为 Go 是开源的。所以我真正想要的是一个“共同 list ”。 已
我已经实现了通用链接。 通用链接适用于原始域,它会在点击 url 时立即打开应用程序。 但我的客户想要 goo.gl 缩短 url,这会导致此处出现问题,并且深层链接没有响应,并且在点击 url 时不
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
如果我没记错的话,GOOS是在编译源代码时确定的。 为了更好地支持多个操作系统,我对 GOOS 可能是什么感兴趣。 当然,它可能有无限的可能性,因为 Go 是开源的。所以我真正想要的是一个“通用列表”
我在下面编写了 Makefile 来为不同平台构建 Golang 代码。 (我的操作系统是Windows 10并通过命令提示符运行Makefile) GOCMD = go GOBUILD =
当使用 Goo.gl API 时,有没有办法告诉它不要自动添加尾部斜杠?因为它弄乱了很多网站,例如如果您访问:http://www.samsung.com/us/support/SupportOwne
我是 HTML5、CSS3 和 jQuery 的新手,想知道如何使用它们创建动态图和饼图等 goo.gl 统计信息。 非常感谢你们的任何帮助。 谢谢,EG 最佳答案 Google 有免费的 chart
我可以使用 goo.gl API 使用以下两行 python 代码创建一个短 URL: longurl = 'http:/www.example.com/url'r = requests
goo gl 可以支持多少个 URL?以及它的当前填充速度是多少。 我可以看到它使用大小字母和数字创建了唯一的 URL。这使它的容量为 (26*2+10)^5,这个估计是否正确。 最佳答案 我认为数学
根据此处缩短的示例 URL: http://goo.gl/info/kW1c#week 显示的二维条形码是什么(在此处复制): 最佳答案 它实际上是一个二维条形码,它是一个QR码。它旨在打印在贴纸上以
继续获取: V/RESPONSE(13605): { V/RESPONSE(13605): "error": { V/RESPONSE(13605): "errors": [ V/RESPON
我目前正在开发一种服务,它可以构建为 Windows 服务或作为 OSX/linux 可执行文件运行。 我在 Windows 文件上使用构建标签,包括带有 main 方法的文件 // +build w
我正在尝试使用 golangs 交叉编译功能在我的机器 (windows 7) 上进行编译,以便在 linux 和 amd64 编译之间切换。 我正确地设置了一切并创建了环境变量 GOARCH = a
我想获取 goo.gl 对给定短网址的所有分析,例如 http://goo.gl/kuBJ7S 我尝试了以下 curl 'https://www.googleapis.com/url
我正在尝试从 Google Apps 脚本中查询 goo.gl API。我看到的问题是以下错误消息: Request failed for https://www.googleapis.com/url
网络摄像头不工作。它在控制台上显示“只允许安全来源”, 我访问服务器中的网络应用程序。我正在使用 192.168.1.11/myApp 访问我的系统。它在 chrome 中不起作用,但在 Firefo
我正在尝试在不使用外部库的情况下使用 Java 执行此操作。我不能使用外部库来执行此操作,因为我没有在这个项目中使用 Maven。 我使用的方法是: public static String shor
我正在将 firebase 集成到应用程序中。我创建了适用于 Android 和 iOS 的通用链接。 效果很好。但是我遇到了这样的情况:我点击了显示在已启动的应用程序右上角的 goo.gl (PFA
出于某种原因,我的脚本今天停止工作。当我查看 API 控制面板时,显示我还有 100% 的剩余使用量。有任何想法吗?他们是否更改了授权方式? function url_small($url)
我是一名优秀的程序员,十分优秀!