新浪微博Oauth2.0授权 获取Access Token以及API的使用
今天需要使用新浪微博提供的API获取微博的详细信息以及用户的详细信息,所以需要使用API中的/statuses/show接口。 使用新浪微博API的前提是需要到新浪微博开放平台注册一个应用,获得App Key和App Secret,然后再根据这两个获取Access Token。下面详细介绍如
今天需要使用新浪微博提供的API获取微博的详细信息以及用户的详细信息,所以需要使用API中的/statuses/show接口。
使用新浪微博API的前提是需要到新浪微博开放平台注册一个应用,获得App Key和App Secret,然后再根据这两个获取Access Token。下面详细介绍如何获取Access Token以及如何使用新浪微博提供的API。
一、获取Access Token
1、进入新浪微博开放平台,进入应用开发,选择创建应用,这里我选择的是“网页应用”
2、填写应用的基本信息
可以随便填写,点击“创建”,就可以创建成功!
创建成功后,可以查看应用的信息。主要需要的是App Key和App Secret。
3、添加授权回调页
选择刚刚创建的应用,进入到应用信息,选择高级信息,添加授权回调页。
这个一定要添加,如果没有授权回调页,是无法获取到Access Token 的,而且必须保证回调页的网址时可以访问的。
4、获取新浪微博SDK包
在新浪微博开放平台,选择文档->资源下载->SDK下载,我选择Java SDK的版本。下载完成后,解压缩,将项目导入到Eclipse中。
可以查看一下文档:readme.txt,内容为:
[plain] view plaincopyprint?
- 请先填写相关配置:在Config.properties里
- client_ID :appkey
- client_SERCRET :app_secret
- redirect_URI : 回调地址
5、配置SDK开发包
打开Config.properties文件(在src目录下)
[plain] view plaincopyprint?
- client_ID =
- client_SERCRET =
- redirect_URI =
- baseURL=https://api.weibo.com/2/
- accessTokenURL=https://api.weibo.com/oauth2/access_token
- authorizeURL=https://api.weibo.com/oauth2/authorize
- rmURL=https://rm.api.weibo.com/2/
6、获取Access Token
打开example资源文件夹下,weibo4j.examples.oauth2文件夹下的OAuth4Code.java
将代码:
[plain] view plaincopyprint?
- BareBonesBrowserLaunch.openURL(oauth.authorize("code",args[1],args[2]));
- System.out.println(oauth.authorize("code",args[1],args[2]));
[plain] view plaincopyprint?
- BareBonesBrowserLaunch.openURL(oauth.authorize("code","",""));
- System.out.println(oauth.authorize("code","", ""));
然后选择run as Java Application,打开了浏览器,即打开的是你填写的回调地址,注意查看此时的url,最后一部分是code=XXXXXXXXXXXXXXXXXXXXX。复制这个code的值。查看Eclipse的控制台窗口:
输入刚刚获得的code值,点击回车。
这时已经获得了access_token值和uid的值,现在你就可以使用access_token来运行example中的程序了。注意,access_token的值有一定的时效性,access_token失效后需要重新申请一下,即重复第6步,每次access_token的值是不会改变的。
二、运行example实例程序
我选择的是weibo4j.examples.timeline中的ShowStatus.java。将access_token换成刚才得到的值,id指的是微博的ID,运行,即可得到有关微博的信息以及用户的信息。
其他的程序也是相同的道理。
http://blog.csdn.net/xyw_eliot/article/details/8907918

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



1. Open settings in Windows 11. You can use Win+I shortcut or any other method. 2. Go to the Apps section and click Apps & Features. 3. Find the application you want to prevent from running in the background. Click the three-dot button and select Advanced Options. 4. Find the [Background Application Permissions] section and select the desired value. By default, Windows 11 sets power optimization mode. It allows Windows to manage how applications work in the background. For example, once you enable battery saver mode to preserve battery, the system will automatically close all apps. 5. Select [Never] to prevent the application from running in the background. Please note that if you notice that the program is not sending you notifications, failing to update data, etc., you can

DeepSeek cannot convert files directly to PDF. Depending on the file type, you can use different methods: Common documents (Word, Excel, PowerPoint): Use Microsoft Office, LibreOffice and other software to export as PDF. Image: Save as PDF using image viewer or image processing software. Web pages: Use the browser's "Print into PDF" function or the dedicated web page to PDF tool. Uncommon formats: Find the right converter and convert it to PDF. It is crucial to choose the right tools and develop a plan based on the actual situation.

Oracle can read dbf files through the following steps: create an external table and reference the dbf file; query the external table to retrieve data; import the data into the Oracle table.

The Java reflection mechanism allows programs to dynamically modify the behavior of classes without modifying the source code. By operating the Class object, you can create instances through newInstance(), modify private field values, call private methods, etc. Reflection should be used with caution, however, as it can cause unexpected behavior and security issues, and has a performance overhead.

Common exception types and their repair measures in Java function development During the development of Java functions, various exceptions may be encountered, which affect the correct execution of the function. The following are common exception types and their repair measures: 1. NullPointerException Description: Thrown when accessing an object that has not been initialized. Fix: Make sure you check the object for non-null before using it. Sample code: try{Stringname=null;System.out.println(name.length());}catch(NullPointerExceptione){

Ways to solve iframe cross-domain issues in Vue: CORS: Enable CORS support in the backend server and use XMLHttpRequest or fetch API to send CORS requests in Vue. JSONP: Dynamically load JSONP scripts in Vue using the JSONP endpoint in the backend server. Proxy server: Set up a proxy server to forward requests, use a third-party library (such as axios) in Vue to send requests and set the proxy server URL.

Yesterday, BotanixLabs announced that it has completed a total of US$11.5 million in financing, with participation from Polychain Capital, Placeholder Capital and others. Financing will be used to build the decentralized EVM equivalent of BTCL2Botanix. Spiderchain combines the ease of use of EVM with the security of Bitcoin. Since the testnet went live in November 2023, there have been more than 200,000 active addresses. Odaily will analyze Botanix’s characteristic mechanism and testnet interaction process in this article. Botanix According to the official definition, Botanix is a decentralized Turing-complete L2EVM built on Bitcoin and consists of two core components: Ethereum Virtual Machine

The EXPLAIN command in Oracle is used to analyze the execution plan of a SQL statement. The method of use is to add the EXPLAIN keyword before the SQL statement. EXPLAIN results contain information such as ID, operator type, row count estimate, cost estimate, output row count estimate, access predicates, and filter predicates, which can be used to optimize query performance, identify costly operators, and tables that may benefit from optimization techniques.
