Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching profile image #44

Closed
trante opened this issue Apr 14, 2012 · 2 comments
Closed

Fetching profile image #44

trante opened this issue Apr 14, 2012 · 2 comments
Assignees
Labels

Comments

@trante
Copy link

trante commented Apr 14, 2012

I'm trying to get profile image. I couldn't find an example in library.
So i used this code:
$params = array( 'screen_name' => $scrName );
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1/users/profile_image') , $params);

But the output is as follows:
< html > < body >You are being redirected.< /body >< /html >

Is it possible to fetch image link by tmhOAuth library?

@themattharris
Copy link
Owner

The profile image URL is located in the user object and it's generally better to get it through /1/users/lookup instead.
(https://dev.twitter.com/docs/api/1/get/users/lookup).

But, to answer your question, the Twitter API documentation for https://dev.twitter.com/docs/api/1/get/users/profile_image/%3Ascreen_name says This resource does not return JSON or XML, but instead returns a 302 redirect to the actual image resource.. This means you need to look at the headers of $tmhOAuth response to get the profile image URL.

If you wish to use $tmhOAuth as the way to get these images for caching you can do something like this:

$code = $tmhOAuth->request('GET', $tmhOAuth->url('1/users/profile_image'), array(
  'screen_name' => 'themattharris',
));

if ($code == 302) {
  $profile_image = $tmhOAuth->response['headers']['location'];
}

Hope that helps.

@ghost ghost assigned themattharris Apr 14, 2012
@trante
Copy link
Author

trante commented Apr 15, 2012

Thank you, that helped much.

@trante trante closed this as completed Apr 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants