新浪微博实验碰到的问题总结和解决办法(Java)

按照新浪提供的例子:https://github.com/sunxiaowei2014/weibo4j-oauth2-beta3.1.1
碰到以下问题:

1. 运行代码出现error:redirect_uri_mismatch
运行新浪提供的Java示例出现此错误:


问题
此错误表示在本地config.properties里填写的 redirect_URI与微博开放平台上应用的设置不一致。

解决办法:
登录微博开放平台http://open.weibo.com,然后点击:我的应用 -> {应用名字} -> 应用信息 -> 高级信息。然后编辑OAuth2.0 授权设置:


请确保授权回调页和本地Config.properties里的 redirect_URI项的值一致。

2. 登录和授权都成功, 但取不到accessToken
以下是日志
https://api.weibo.com/oauth2/authorize?client_id=xxxxxxxxxx&redirect_uri=https://api.weibo.com/oauth2/default.html&response_type=code
Hit enter when it's done.[Enter]:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0    INFO  [2014-10-11 22:14:20]  code: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2    DEBUG [2014-10-11 22:14:20]  Request:
2    DEBUG [2014-10-11 22:14:20]  POSThttps://api.weibo.com/oauth2/access_token
1209 DEBUG [2014-10-11 22:14:21]  Response:
1209 DEBUG [2014-10-11 22:14:21]  https StatusCode:401
1210 DEBUG [2014-10-11 22:14:21]  Server:nginx/1.2.0
1210 DEBUG [2014-10-11 22:14:21]  Date:Sat, 11 Oct 2014 14:13:29 GMT
1210 DEBUG [2014-10-11 22:14:21]  Transfer-Encoding:chunked
1210 DEBUG [2014-10-11 22:14:21]  Connection:keep-alive
1210 DEBUG [2014-10-11 22:14:21]  Pragma:No-cache
1210 DEBUG [2014-10-11 22:14:21]  Cache-Control:no-cache
1210 DEBUG [2014-10-11 22:14:21]  Expires:Thu, 01 Jan 1970 00:00:00 GMT
1211 DEBUG [2014-10-11 22:14:21]  Api-Server-IP:10.73.89.48
1215 WARN  [2014-10-11 22:14:21]  Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
1216 DEBUG [2014-10-11 22:14:21]  {"error":"invalid_client","error_code":21324,"request":"/oauth2/access_token","error_uri":"/oauth2/access_token","error_description":"client_secret error."}

weibo4j.model.WeiboException   : 401:Authentication credentials were missing or incorrect.
 error:invalid_client error_code:21324/oauth2/access_token
1222 INFO  [2014-10-11 22:14:21]  Unable to get the access token.
       at weibo4j.http.HttpClient.httpRequest(   HttpClient.java:403 )
       at weibo4j.http.HttpClient.post(   HttpClient.java:293 )
       at weibo4j.Oauth.getAccessTokenByCode(   Oauth.java:79 )
       at weibo4j.examples.oauth2.OAuth4Code.main(   OAuth4Code.java:21 )

问题所在
config.properties里的client_ID和 client_SERCRET的值中空格

解决办法:
删除值前后的空格,保证 client_ID和 client_SERCRET与微博开放平台上你应用基本信息的App Key和 App Secret一致。

3. 运行ShowUser.java出现错误: 21321: applications over the unaudited use restrictions!

解决办法:未审核应用需要添加测试用户,在open.weibo.com的管理中心添加
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值