Is there a quick way to pull twitter profile image in PHP or Javascript? I need to get the url of the FULL image (not avatar size). Thanks. Any code sample is good.
Twitter has had a nice simple URL.
https://api.twitter.com/1/users/profile_image/abraham
It has size options like "?size=bigger"
You can read more about it on Little known Twitter and TwitterAPI tips and tricks.
Twitter now has documentation up as GET users/profile_image/:screen_name.
Update: Support for this method has been removed from v1.1 of the API. Recommended practice going forward is GET /users/show and cache profile_image_url locally in your service/app.
function get_big_profile_image($username, $size = '') {
$api_call = 'http://twitter.com/users/show/'.$username.'.json';
$results = json_decode(file_get_contents($api_call));
return str_replace('_normal', $size, $results->profile_image_url);
}
get_big_profile_image('bobsaget', '_bigger') should return a large avatar:
http://a1.twimg.com/profile_images/330305510/n229938150541_9850_bigger.jpg
get_big_profile_image('bobsaget') should return an even larger image: http://a1.twimg.com/profile_images/330305510/n229938150541_9850.jpg
Apologies if this is something that's now known, but I didn't see it documented anywhere during my searches, including the official Twitter docs.
You can add the ?size=original as a parameter, which will return the original uploaded image for the user.
So:
http://api.twitter.com/1/users/profile_image/twitter.json?size=original
Previous answerers have provided the correct answer I wanted to link to original twitter api doc page so you'd know it is actually an official way of doing stuff:
You need to specify ?size=
bigger - 73px by 73px
normal - 48px by 48px
mini - 24px by 24px
http://api.twitter.com/1/users/profile_image/twitter.json?size=bigger
http://api.twitter.com/1/users/profile_image/twitter.json?size=normal
http://dev.twitter.com/doc/get/users/profile_image/:screen_name
So, it's not in the docs (http://dev.twitter.com/doc/get/users/profile_image/:screen_name), but it looks like after retrieving the image by specifying any of the three sizes (bigger, normal, mini), you can just remove the suffix before the file extension to get the original image. Hmm... is this safe to use?
For example, this query: api.twitter.com/1/users/profile_image/rrbrambley
Results in: a2.twimg.com/profile_images/931772958/deformed_cropped_headonly_normal.jpg
If I change this url by removing "_normal" then I get the original image: a2.twimg.com/profile_images/931772958/deformed_cropped_headonly.jpg
I know there are apps that use the original image. This must be the way?
When you get original image link, you can modify it to get bigger.
http://pbs.twimg.com/profile_images/34543543/image_name_normal.jpg
becomes
http://pbs.twimg.com/profile_images/34543543/image_name.jpg or image_name_bigger, ...
Source: https://dev.twitter.com/docs/user-profile-images-and-banners
I know this isn't the full code sample as requested (because there are several ways of doing this), but do you already have the URL for the avatar? I noticed that turning ".../eric.png" into ".../eric_bigger.png" resulted in the larger image. When "_bigger" already exists, removing it gave me the URL to the original image.
I tested this with several followers' profile images and, when the profile image was > 150px square, worked.
Twitter profile images urls:
Bigger: https://api.twitter.com/1/users/profile_image/puneetsindhwani/?size=bigger
Original: https://api.twitter.com/1/users/profile_image/puneetsindhwani/?size=original
Related
My site has a feature where users can upload a link to their google docs file. What I want to do is list all the uploaded links in a place. While doing that I need to show the name of the file that is associated with the link.
I can extract the file id from the link and make sure the link is of google docs. Now I need to find a way to get the filename from that. I tried going through the google developer API for google drive, but it is for uploading/doing anything only on the authorized docs. My issue here is, my users upload the files manually to their docs which I have no control over. All I get is a sharable link and somehow get the name out of it. In addition, a thumbnail will also help.
I have tried doing this, but it throws error
$url = "https://www.googleapis.com/drive/v3/files/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA";
// and
$url = "https://docs.google.com/document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing"
$html= file_get_contents($url);
print_r($html);
A dummy link for anyone willing to help: https://docs.google.com/document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing
Since we are getting the URL to the file, we can do a couple of things -
get the id to the file
get what type of file is that
Before I explain how to do that, it is better to know that there can be 2 possible situations. One the file is a google docs file, the other google drive file. Those both start with different URLs.
$url = explode('/', Str::after(
Str::after($request->url, 'https://docs.google.com/'), 'https://drive.google.com/'
));
I am using 2 Str::after() to remove the unnecessary part from the URL. Then I am using explode to convert the URL into an array.
Since we have excluded the useless part from the URL, we are left with document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing in an array form.
So, if we try to do $url[2], we get the id of the file. Also, "document" is also a good thing to note about. I use those to show proper images. There can be 5 different types of them (4 for google docs and 1 for google drive). Those are - document, spreadsheets, forms, presentation for google docs, and file for google drive. I would recommend everyone store these in the database so that extra calculations are not necessary while displaying it.
Now, to answer the actual part of the question. How to get the name. I have created a new model method to handle that.
public function name()
{
$key = config('app.google_api_key');
$url = "https://www.googleapis.com/drive/v3/files/{$this->file_id}?key={$key}";
$response = Http::get($url)->json();
return $response['name'] ?? 'Private File';
}
Don't forget to add your Google API key in the config file app.php (You need to create one). You can get your API key from Google Developer Console and create a project-specific key. Just to note that this key need not be belonging to the user of the URL.
Also, a thing to note here is that $response returns error code if the file is not set to visible to the public or the file is deleted.
I'm brand new to APIs so please excuse what is probably a long and stupid question. Can I modify this code I got from this sample script - https://developers.google.com/youtube/v3/code_samples/php#update_a_video_by_adding_new_tags - to return the original name of the uploaded file for one of my company's videos? Note: I have already modified the linked script to remove the updating of tags (i.e. I just had it print the video id and the current tags to test that I had the Oauth2 working and I did - so, I got that far at least.)
// Call the API's videos.list method to retrieve the video resource.
$listResponse = $youtube->videos->listVideos("snippet",
array('id' => $videoId));
I was thinking that changing to "snippet" to "fileDetails" is what I need. If so, then how do then extract just the original filename from $listResponse?
Welcome to the world of Google Development. Lets look at the documentation a little for videos.list.
If you check under response you will notice that it returns an array of video resources click on that and the documentation will take you to Videos resource representation as you can see there is lots of fun stuff here. Under snippet you find title.
snippet.title string The video's title. The property value has a
maximum length of 100 characters and may contain all valid UTF-8
characters except < and >. You must set a value for this property if
you call the videos.update method and are updating the snippet part of
a video resource.
On the main videos.list documentation page you will find some examples of how to use it with PHP. Here is a hunk of the first one I think you will like.
// Display the list of matching videos.
foreach ($videosResponse['items'] as $videoResult) {
$videos .= sprintf('<li>%s </li>',
$videoResult['snippet']['title']);
}
Googles documentation is very useful always check it.
i got image url saved in my database.i am using php and mysql.
Some images can be displayed but others are restricted.At the moment restricted image show up broken on my site.
I only which to display non restricted images.
url for image that can be shown is
http://images.icecat.biz/img/gallery/16678932_9061.jpg
restricted image is
http://images.icecat.biz/img/gallery/8622798_7908.jpg
i have tried getimagesize but cant seem to be having any luck.
kind regards
nafri
file_exists() doesn't work across domains. Server side can be done like:
$url = 'http://images.icecat.biz/img/gallery/16678932_9061.jpg';
$header = get_headers($url, 1);
if(strpos( $header[0],'200') === false){
// do what ever
}
EDIT: fixed for 200 response. Better use curl though, faster it is
If you're happy to handle this on the client side, then you could use javascript to deal with this:
You can use handle the onError event to replace the image or do something else in the event that the image cannot be displayed.
See this answer for an example.
In my local webserver, I'm trying to generate the text for pasting to my blog, followed by below question:
How to get static image url from flickr URL?
<a href="http://www.flickr.com/photos/53067560#N00/2658147888/" title="Chou fleurs by Nicolas de Fontenay, on Flickr">[<img src="https://i.stack.imgur.com/VC7Ng.jpg" width="500" height="375" alt="Chou fleurs">][1]
I think it's good to use some API function and to designate $variables to:
53067560#N00
2658147888
"Chou fleurs by Nicolas de Fontenay, on Flickr"
"http://farm4.staticflickr.com/3221/2658147888_826edc8465.jpg"
"500"
"375"
"Chou fleurs"
, but don't know how to code in detail. Ideally, a function
getFlickrImageURLforGrab(name of Set, # of photos)
ex.) getFlickrImageURLforGrab(myset1, 10) returns first 10 photo's URLs in the Set myset1 are displayed. Would you please show a simple php example?
The answers in the question you link to refer to flickr.photos.getSizes. You also will want to look at the doc for flickr.photosets.getPhotos.
I don't use PHP with Flickr's API, but a search turns up phpFlickr, which might help you with some of the heavy lifting.
I have implemented a image gallery where in each image is differentiated by its record id . the like button works properly for rest of images only for two images its not working as intended , this is the post content sent by the image that is working properly
connect_text 0
edge_type like
fb_dtsg AQC7N-EB
href http://www.mydomain.com/images/p.php?id=2422
iframe_referer http://www.mydomain.com/index.php
is_personalized false
layout button_count
lsd
node_type link
now_connected true
page_id
post_form_id 7500ee8867c2d00acc75d7b6dfe2c733
post_form_id_source AsyncRequest
ref
and the facebook response for this is :
for (;;);{"__ar":1,"payload":{"requires_login":false,"error_info":null,"show_error":false,"node_type":"ExternalLink","node_id":"10150246004339081","edge_type":"ExternalLinkLike","connect_text":0,"success":true,"already_connected":true,"user_profile":{"name":"Mamamia","profile_url":"http:\/\/www.facebook.com\/profile.php?id=100002607508082","pic_square":"http:\/\/profile.ak.fbcdn.net\/static-ak\/rsrc.php\/v1\/yo\/r\/UlIqmHJn-SK.gif"},"story_fbid":107571802673069,"is_admin":false,"admin_url":""},"invalidate_cache":[0]}
while for the faulty image post data is
connect_text 0
edge_type like
fb_dtsg AQC7N-EB
href http://www.mydomain.com/images/p.php?id=2420
iframe_referer http://www.mydomain.com/index.php
is_personalized false
layout button_count
lsd
node_type link
now_connected true
page_id
post_form_id 7500ee8867c2d00acc75d7b6dfe2c733
post_form_id_source AsyncRequest
ref
and its response is
for (;;);{"__ar":1,"payload":{"requires_login":false,"success":false,"already_connected":false,"is_admin":false,"show_error":false,"error_info":null}}
can any body tell me why like buttons are working on some images are not working on others t ? the images content is brought from database and is linked in the page by looping the array in foreach condition so hyperlinks are same except for the id of image,the hyperlink is
http://www.facebook.com/plugins/like.php?href=http://www.mydomain.com/images/p.php?id=<?php echo $array[id]; ?>
thanks in advance
Not a proper answer, so sorry for that. But I'm experiencing the same problem exactly. It looks like facebook simply has a problem with certain GET variables in URLs. I can't think of any other explanation, it works for some and not others. The ones it doesn't work for appear to be random.
I think this must be a facebook bug. The only thing I can think to do is to either submit the bug or sit tight and hope they've spotted the problem and are working on it! Pain in the arse, mind.
EDIT: Well, I've got a workaround. Just add a random GET variable to your URL string. I went with 's=true' and that worked. Weird stuff, it must mistake URLs ending in certain numbers as character entities.
I had the same error in my header. It seems the url (domain) did not
pass the validation by facebook. In my case, i had 2 dots in it.
www.somedomain.net16.net (just a working domain)
To see if facebook can retreive data from your site use this url:
http://developers.facebook.com/tools/debug/
To test it, just type www.google.nl and you get all kind of information back.
Use facebook's iframe suggested code which can be obtained here
http://developers.facebook.com/tools/lint/