How to get user image with Twitter API 1.1?

后端 未结 6 2083
眼角桃花
眼角桃花 2020-12-02 17:45

In API 1.0, we can use users/profile_image/:screen_name

For example : http://api.twitter.com/1/users/profile_image/EA_FIFA_FRANCE

B

6条回答
  •  Happy的楠姐
    2020-12-02 18:05

    As the previous answers and comments point out:

    1. Twitter API v1.0 is deprecated
    2. Twitter API v1.1 requires OAuth
    3. OP (@Steffi) doesn't want to authenticate

    Pick any two; with all three it's a no-go. @Jimbo's answer is correct (and the proper way to do it), but excludes #3. Throwing out #1 means going back in time. But, we can throw out #2, and go directly to the source:

    curl -s https://twitter.com/EA_FIFA_FRANCE |
      sed -ne 's/^.*ProfileAvatar-image.*\(https:[^"]*\).*$/\1/p'
    

    The sed command just says, find the line that contains "ProfileAvatar-image" and print the substring that looks like a quoted URL.

    This is less stable than an authenticated API call, since Twitter may change their HTML at any time, but it's easier than dealing with OAuth, and no official rate limits!

    The PHP translation should be straightforward.

提交回复
热议问题