01-get three Twitter user profile paths | 07. Miscellaneous

Source: Internet
Author: User
ArticleDirectory
    • 1. 0. Background
    • 1.1.twitter API is applicable to yql
    • 1.2.yql Python package Library
    • 1. 3. Request restrictions
    • 1.4.yql console Web Page Test
    • 1.5.python yql call Method
    • 2. 1. Request restrictions
    • 3. 1. Request restrictions
01-how to get Twitter user profile

Zheng Yi 201005 is affiliated with section 07. Miscellaneous

There are three methods. Of course, there will be more public third-party Twitter proxy APIs.

Since each method has a request frequency limit, it is recommended that the finalProgramTo mix these three methods, either randomly select one of them or access them one by one based on the priority. If the access fails, immediately switch to the following method.

 

1. yql Method

Yql and Yahoo! PIPE is one of the best mashup tools. As a geek, you must be familiar with Yahoo! Pipe.

1. 0. Background

The mechanism behind yql released by Yahoo is that everyone can use its data in a special way for others. Who wants to read the data, you only need to use a language similar to SQL syntax.

It is an online query processor with a rest-based interface that allows developers to query data from various resources.

It is a strict Query Processing hosting service. This also means that yql is not subject to individual data resource restrictions, or even applies to Yahoo's own products. Yql can operate any third-party data source, as long as the other party is in a common format, such as RSS, Atom, JSON, XML, and so on.

For more information, see Interactive encyclopedia.

1.1.twitter API is applicable to yql

As mentioned above, yql can be used as a data source as long as the recipient is a common data format, such as JSON and RSS. Therefore, when we are restricted by the frequency of access to Twitter, we can follow this path.

1.2.yql Python package Library

Python yql Library Home Page address: http://python-yql.org/

Easy to install: easy_install yql. Ease of use:

 
>>> Import yql
>>> Y = yql. Public ()
>>> Query = 'select * from Flickr. Photos. Search where text = "Panda" Limit 3 ';
>>> Result = y.exe cute (query)
>>> Result. Rows
 
 

However, be careful that the yql database actually assembles an http url for querying yql and initiates a request using a custom or externally passed-In httplib2 instance, which is bound to be affected by the network environment, for example, GFW interference.

1. 3. Request restrictions
 
In usage information and limits, yql says:

    • Per application limit (identified by your access key ):100,000 cballs per day.
    • Per IP limits:/V1/public /*:1,000 CILS per hour;/V1/yql /*:10,000 CILS per hour.
    • All rates are subject to change.
    • Yql rate limits are subject to the rate limits of other yahoo! And 3rd-party Web Services.

1.4.yql console Web Page Test

Enter the http://developer.yahoo.com/yql/console/ page,

In the your yql statement input box, enter the following SQL command:

Select * From JSON where url = 'HTTP: // api.twitter.com/1/users/show/fenng.json'

Click the "test" button. Later, the formatted view will display the fenng profile of the Twitter user in XML format.

 

SQL commands

Select * From JSON where url = "http://search.twitter.com/search.json? Q = RT & RPP = 20 & lang = ZH"
You can obtain the latest RT message through the Twitter search interface.

 

SQL commands

Select * From JSON where url = 'https: // twitter.com/statuses/user_timeline/fenng.json'

Several pieces of tweets recently released by fenng can be obtained.

 

1.5.python yql call Method

For requests from other data sources, such as Flickr, yql databases will not have any problems in our network environment. However, for the Twitter data source, it seems easy to reset the Link (but it is okay to access the yql console in the browser for query. So it may be about User-Agent .), Therefore, we need to set up a proxy to penetrate the wall. When the proxy chooses puff, it seems that the 401 HTTP status is easily obtained, so mr. Zhang is selected.

CodeAs follows:

Import yql
Import httplib2
Import socks
H = httplib2.http (proxy_info = httplib2.proxyinfo (socks. proxy_type_http, 'localhost', 2010 ))
Y = yql. Public (httplib2_inst = H)
Resultspolicy.exe cute ("select * From JSON where url = 'HTTP: // api.twitter.com/1/users/show/fenng.json '")
Print results. Rows
Print results. Uri

(Note: SOCKS library needs to be installed, home address: http://socksipy.sourceforge.net/, it has no installer, downloadSource codePackage copy socks. py to Python's lib/Site-packages directory. For httplib2, install httplib2 with easy_install .)

You can also regard yql as a proxy to convert any data format to a proxy in the specified format.

2. socialgraph

The lookup method of Google social graph can obtain the association information of a Twitter user.

We can assemble such a URL:

Http://socialgraph.apis.google.com/lookup? Q = Twitter.com % 2 fzhengyun & pretty = 1

To get zhengyun's Twitter profile. The result is as follows:

{
"Canonical_mapping ":{
"Twitter.com/zhengyun": "http://twitter.com/zhengyun"
},
"Nodes ":{
"Http://twitter.com/zhengyun ":{
"Attributes ":{
"FN": "zhengyun ",
"ADR": "\ u5317 \ u4eac ",
"Photo": "http://a1.twimg.com/profile_images/27832922/zhengyun_ustc_bigger.jpg ",
"Exists": "1 ",
"RSS": "http://twitter.com/statuses/user_timeline/zhengyun.rss ",
"Atom": "http://twitter.com/statuses/user_timeline/zhengyun.atom ",
"Url": "http://twitter.com/zhengyun ",
"Profile": "http://twitter.com/zhengyun"
}
}
}
}

Of course, this is not all the data provided by Twitter's own API, but it is also possible to obtain the most basic fields such as the user's location (that is, the ADR field) and profile picture (photo field.

2. 1. Request restrictions

Google wrote: "Use of the Social Graph API is subject to a query limit50,000 queries per user per day.If you go over this 24-hour limit, the social Graph API may stop working for you temporarily. if you continue to exceed this limit, your access to the social Graph API may be blocked ", it seems that you need to know which exception is triggered when" stop working for you temporarily "is detected, in this way, block is avoided.

3. Twitter

Finally, you can directly access the Twitter user/show method:
Http://api.twitter.com/1/users/show.xml? Id = noradio
Instead of requesting the statuses/user_timeline method.
Example:
Http://api.twitter.com/1/users/show.json? Id = zhengyun

 

3. 1. Request restrictions

If our egress IP address is on the Twitter White List, the access limit is: 20,000 requests per hour. Otherwise it is 150 ~ 350 times.

 

Appendix:

Query command of Python yql Library

Select * From JSON where url = "http://api.twitter.com/1/users/show/fenng.json"

An HTTP request is actually assembled:

Http://query.yahooapis.com/v1/yql? Q = select % 20 * % 20 from % 20 JSON % 20 where % 0a % 20url % 3d % 22 HTTP % 3A % 2f % 2fapi.twitter.com % 2f1% 2 fusers % 2 fshow % 2ffenng. JSON % 22 & diagnostics = true

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.