Getting a users Profile picture

Im having trouble getting the users Twitch Profile picture once logged in to my site.

Here is the code im using

 Twitch.init({clientId 627272'}, function(error, status) {
 	
 	console.log(status);

 	if (status.authenticated) {
 		$('.twitch-connect').hide();

 		getInfo(function(data) {
 			$('user').text(data.display_name);
 			$('#picture').attr('src','data.display_avatars');
 			$('#visit').text('Channel').attr('href','data.display_channel');
 		});
 	} else {
 		$('#login-info').hide();
 	}   

 });

The display username works perfect but I cannot get the profile picture to work.

Im really sorry, I have never done dev work with twitch so im a little confused.

Thanks.

I’m assuming you’re using the /channel endpoint as documented at https://github.com/justintv/Twitch-API/blob/master/v3_resources/channels.md#get-channel

As you can see in the sample response, display_avatars and display_channel aren’t valid keys. You likely want logo and url instead.

Thanks man, so exactly how would I apply that.

Im having a little trouble I think I have taken bits and pieces of different guides and completely confused myself with how it works.

Sorry again.

Again, this is assuming you’re using the correct endpoint. Post the source to getInfo(callback) if this doesn’t end up working.

 Twitch.init({clientId: '627272'}, function(error, status) {
 	console.log(status);
 	if (status.authenticated) {
 		$('.twitch-connect').hide();
 		getInfo(function(data) {
 			$('user').text(data.display_name);
 			$('#picture').attr('src',data.logo);
 			$('#visit').text('Channel').attr('href',data.url);
 		});
 	} else {
 		$('#login-info').hide();
 	}   
 });

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.