Giter Site home page Giter Site logo

sinaweibopy3's Introduction

Description

sinaweibopy3 plays a role in the use of sinaweibo API just as what Twurl does in the use of Twitter API. It asks for the authorization of a specified user to get the access token for the client application, and then signs all requests with that access token.

Specifically, sinaweibopy3 is for python3 version. If you're using python 2, please click here: sinaweibopy

Getting Started

If you start to use sinaweibo API from scratch, the first thing is to apply for a developer account to access sinaweibo API:

https://open.weibo.com/wiki/API

After you have that access you can create a new app and generate a App Key and App Secret.

When you have your App Key and Secret you authorize your sinaweibo account to make API requests with your App Key and Secret. This will return an URL that you should open up in your browser. Authenticate to sinaweibo, and then enter the returned token code back into the terminal. Assuming all that works well, you will be authorized to make requests with the API. Sounds complicated? Don't worry, sinaweibopy3 will do the work for you.

Usage

  1. Import sinaweibopy3 in your file
import webbrowser
import sinaweibopy3
  1. Set some parameters of your application: APP_KEY, APP_SECRET, REDIRECT_URL

  2. Use sinaweibopy3 to get the access token for the application.

client = sinaweibopy3.APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=REDIRECT_URL)
url = client.get_authorize_url()
webbrowser.open_new(url)
result = client.request_access_token(input("please input code : "))
client.set_access_token(result.access_token, result.expires_in)
  1. Make requests with API using the access token.

Example: To get some of the latest public microblogs and the user information:
print(client.public_timeline())

The data is in json. you can further parse it and extract the information you need.

What should I do if I want to get other kinds of data from sinaweibo API?

  1. Look up the required url and parameters of the data on https://open.weibo.com/wiki/API url parameters
  2. In sinaweibopy3.py, add a function.
def funtion_name(self):
  result = _http_get('%s'% (self.api_url)  + 'the remaining part of url after extracting https://api.weibo.com/2 ',
             other requirement parameters, such as:
             access_token=self.access_token,
             ...
              )
      return result  
  1. Call the fuction in your file by: result=client.funtion_name()

If the fuction works well, you'll get the required data. Good Luck!

sinaweibopy3's People

Contributors

olwolf avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.