Hack Forums
[C#] Skype Avatar Grabber - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Skype Avatar Grabber (/showthread.php?tid=5444484)



Skype Avatar Grabber - true - Oct 25, 2016

A lot of Skype tools use the website to get user profiles off of. This is a problem, because a lot of people have privacy settings on their profiles. For this reason, I made a class that has two options for avatar grabbing: The site, or the API. The difference between using the site and the API, is that if the user is on your contacts, the SKYPE4COMLIB API will 100% download their profile picture. How I'd recommend using this class, is doing a check if the user that's handle is trying to be grabbed is on your contacts list, then call either method accordingly.

Code
using SKYPE4COMLib;
using System.Drawing;
using System.IO;
using System.Threading;

namespace skypeTest
{
    class avatarGrabber
    {
        private Skype s;

        public avatarGrabber(Skype S)
        {
            s = S;
        }

        public Bitmap grabAvatarAPI(string handle) //Saves users image from Skype using the API, then returns it as bitmap
        {
            Command c = new Command();
            File.Delete(Path.GetTempPath() + handle + ".png");
            c.Command = string.Format("GET USER {0} AVATAR 1 {1}", handle, Path.GetTempPath() + handle + ".png");
            s.SendCommand(c);
            Thread.Sleep(100); //THIS IS MANDATORY
            return new Bitmap(Path.GetTempPath() + handle + ".png");
        }

        public string grabAvatarOnline(string handle) //Downloads it off Skypes website. You get the profile picture as if you aren't a contact. returns string
        {
            return "http://api.skype.com/users/" + handle + "/profile/avatar";
        }
    }
}


Usage Examples:

Initialization

Code
avatarGrabber a = new avatarGrabber(nameOfSkype)

Grab picture from API and put it in pictureBox

Code
pictureBox1.Image = a.grabAvatarAPI("insertaccountnamehere");

Grab picture from site and put it in pictureBox

Code
pictureBox1.ImageLocation = a.grabAvatarOnline("insertaccountnamehere");

I hope someone somewhere will find this useful. Feel free to critique my code, too.


* - Ninja - Oct 26, 2016

You should add the site as fallback method. So the class tries to first get the profile picture via the SKYPE4COM lib and if that doesn't work then it uses the site.


* - esenrik - Dec 10, 2016

Hello! is working for you a message send?