Help - Search - Members - Calendar
Full Version: how to add a friend via API?
Skype Community > English > Development, Betas and Skype Garage > Skype Public API
Good deal
Hello,

I'm learning API documents and cannot find a way to add a User to Friends List.

When I tried "skype.Friends.Add(user)", nothing was happended.

Can anybody help me?

Thanks beforehand.

Sincerely yours,

Good deal
Good deal
up
Good deal
up
TheUberOverlord
Turns out you will need to use the command interface to the API from what I can tell from limited testing:

The SET USER <USERNAME> BUDDYSTATUS 2

If you want to change the text on the add contact request you can also use this command:

SET USER <USERNAME> BUDDYSTATUS 2 <MESSAGE> - add user into contactlist and ask authorization with message.

An Example of how to send an API command via Skype4COM lib can be seen here for C#:

http://forum.skype.com/index.php?s=&sh...st&p=320792
bbil
QUOTE(TheUberOverlord @ Sun Feb 18 2007, 04:35) [snapback]361101[/snapback]

Turns out you will need to use the command interface to the API from what I can tell from limited testing:

The SET USER <USERNAME> BUDDYSTATUS 2

If you want to change the text on the add contact request you can also use this command:

SET USER <USERNAME> BUDDYSTATUS 2 <MESSAGE> - add user into contactlist and ask authorization with message.

An Example of how to send an API command via Skype4COM lib can be seen here for C#:

http://forum.skype.com/index.php?s=&sh...st&p=320792




I use this method to add contacts ...
However, some of my friends do not receive the welcome message ..?
How to send it again ..?


merci d'avance.
p-mec
In C#:

User usr = skype.get_User(handle);
usr.BuddyStatus = TBuddyStatus.budPendingAuthorization;

where skype is SKYPE4COMLib.Skype
Dr.O
Since we have a new event "UserAuthorizationRequestReceived(User pUser)" with skype4com 1.0.29, adding a user to userlist would also be fine for my project.
From Api doku I know only a few user settings are writable
QUOTE
Most user properties are read-only. The following properties are read-write and can be modified with the SET command:

* BUDDYSTATUS
o 1 - delete from buddylist
o 2 - add user into contactlist and ask for authorization: SET USER echo123 BUDDYSTATUS 2 Please authorize me

ISAUTHORIZED

* TRUE - authorize user
* FALSE - dismiss authorization for user
...


CODE
pUser.BuddyStatus = TBuddyStatus.budPendingAuthorization;

will add the requesting user to my userlist.
But this command will NOT authorize the requesting user.
So I send a new api command (because the skype4com command: pUser.IsAuthorized = true seems not to work)
CODE
cmd.Command = "SET USER " + pUser.Handle + " ISAUTHORIZED TRUE";


Now, whats the problem:
When using this two commands at "same time" it would add the user but not authorize the user and sometimes in the other way worried.png
Another Problem I found is that the event is fired two times each request!

This is a short demo: (sk is instance of Skype)
CODE
private void sk_UserAuthorizationRequestReceived(User pUser)
        {
            try
            {
                pUser.BuddyStatus = TBuddyStatus.budPendingAuthorization;
                //pUser.IsAuthorized = true;
                cmd = new Command();
                cmd.Id = 323448;
                cmd.Expected = pUser.Handle;
                cmd.Blocking = false;
                cmd.Command = "SET USER " + pUser.Handle + " ISAUTHORIZED TRUE";
                //cmd.Command = "SET USER " + pUser.Handle + " BUDDYSTATUS 2";
                sk.SendCommand(cmd);
                
                sk.SendMessage(pUser.Handle, ".\n" + "TEST MESSAGE");
            }
            catch (Exception e)
            {
            }
        }


Short:
Adding + authorize User at same time seems not to work
The message "TEST MESSAGE" is received/sent 2 times

Any Advice?
Thx a lot
TheUberOverlord
QUOTE (Dr.O @ Thu Jun 5 2008, 11:03)
Go to the original post
Since we have a new event "UserAuthorizationRequestReceived(User pUser)" with skype4com 1.0.29, adding a user to userlist would also be fine for my project.
From Api doku I know only a few user settings are writable

CODE
pUser.BuddyStatus = TBuddyStatus.budPendingAuthorization;

will add the requesting user to my userlist.
But this command will NOT authorize the requesting user.
So I send a new api command (because the skype4com command: pUser.IsAuthorized = true seems not to work)
CODE
cmd.Command = "SET USER " + pUser.Handle + " ISAUTHORIZED TRUE";


Now, whats the problem:
When using this two commands at "same time" it would add the user but not authorize the user and sometimes in the other way worried.png
Another Problem I found is that the event is fired two times each request!

This is a short demo: (sk is instance of Skype)
CODE
private void sk_UserAuthorizationRequestReceived(User pUser)
        {
            try
            {
                pUser.BuddyStatus = TBuddyStatus.budPendingAuthorization;
                //pUser.IsAuthorized = true;
                cmd = new Command();
                cmd.Id = 323448;
                cmd.Expected = pUser.Handle;
                cmd.Blocking = false;
                cmd.Command = "SET USER " + pUser.Handle + " ISAUTHORIZED TRUE";
                //cmd.Command = "SET USER " + pUser.Handle + " BUDDYSTATUS 2";
                sk.SendCommand(cmd);
                
                sk.SendMessage(pUser.Handle, ".\n" + "TEST MESSAGE");
            }
            catch (Exception e)
            {
            }
        }


Short:
Adding + authorize User at same time seems not to work
The message "TEST MESSAGE" is received/sent 2 times

Any Advice?
Thx a lot


I am confused as what you are really doing here trying to push two command texts in one command?

Example:

cmd.Command = "SET USER " + pUser.Handle + " ISAUTHORIZED TRUE";
cmd.Command = cmd.Command + "SET USER " + pUser.Handle + " BUDDYSTATUS 2";
sk.SendCommand(cmd);

That will never work. Also, if you are sending these one at a time are you waiting for a REPLY? before sending the other?

There are Hardcoded Groups and grpUsersWaitingMyAuthorization is one of these Hardcoded groups until the user is authorized. So you can access the User collection for that Hardcoded Group, and simply set BuddyStatus to 2 using Skype4COM Lib for a specific user found in that group.

I have an Example showing these groups in an example program, But....it only shows Onine users in the groups ("Because the program is for call transfer, and you can't transfer a call to a user who is offline"), but it would give you an Idea of what I mean. I provide full source code to the project as well at the bottom of the page:

http://share.skype.com/sites/devzone/2007/...nsfer.html#more

Or Click the Picture


Or Click the Picture


So Once you received the notification ("Using Skype4COM") via UserAuthorizationRequestReceived(User pUser)"

1. Loop thru all your groups, find the grpUsersWaitingMyAuthorization Hardwired Group.

2. Loop thru the User Collection of the grpUsersWaitingMyAuthorization Group looking for (User pUser) returned from UserAuthorizationRequestReceived.

3. Set that user.BuddyStatus = TBuddyStatus.budPendingAuthorization.

There is also a Groups.vbs example included in the .chm help file with 1.0.29.0 .Zip for Skype4COM that shows the HardWired Groups as well.

From the Skype4COM.idl included in the .chm help documentation for .1.0.29.0

CODE
typedef enum TGroupType
00406    {
00407       [helpcontext(17),helpstring(hsGroupType_Unknown)] grpUnknown = -1,
00408       [helpcontext(17),helpstring(hsGroupType_Custom)] grpCustomGroup = 0,
00409       [helpcontext(17),helpstring(hsGroupType_AllUsers)] grpAllUsers = 1,
00410       [helpcontext(17),helpstring(hsGroupType_AllFriends)] grpAllFriends = 2,
00411       [helpcontext(17),helpstring(hsGroupType_SkypeFriends)] grpSkypeFriends = 3,
00412       [helpcontext(17),helpstring(hsGroupType_SkypeOutFriends)] grpSkypeOutFriends = 4,
00413       [helpcontext(17),helpstring(hsGroupType_OnlineFriends)] grpOnlineFriends = 5,
00414       [helpcontext(17),helpstring(hsGroupType_PendingAuthFriends)] grpPendingAuthorizationFriends = 6,
00415       [helpcontext(17),helpstring(hsGroupType_RecentContactUsers)] grpRecentlyContactedUsers = 7,
[b]
00416       [helpcontext(17),helpstring(hsGroupType_WaitMyAuthorization)] grpUsersWaitingMyAuthorization = 8,
[b]
00417       [helpcontext(17),helpstring(hsGroupType_AuthorizedByMe)] grpUsersAuthorizedByMe = 9,
00418       [helpcontext(17),helpstring(hsGroupType_BlockedByMe)] grpUsersBlockedByMe = 10,
00419       [helpcontext(17),helpstring(hsGroupType_UngroupedFriends)] grpUngroupedFriends = 11,
00420       [helpcontext(17),helpstring(hsGroupType_SharedGroup)] grpSharedGroup = 12,
00421       [helpcontext(17),helpstring(hsGroupType_ProposedSharedGroup)] grpProposedSharedGroup = 13
00422    } TGroupType;


NOTE: The grpPendingAuthorizationFriends hardwired group is the names of Skype Users that have NOT approved YOU yet ;-)
Dr.O
QUOTE
I am confused as what you are really doing here trying to push two command texts in one command?

Of course not wink.png I have forgotten to delete this line out of the demo (at least it was commented out)

Ok now I will have a look to the hardwiredgroups

TheUberOverlord
OK. Just wanted to make sure we were talking about the same thing.
Dr.O
Found out what it was smile.png
First the working code snipped
CODE
GroupCollection gc = sk.HardwiredGroups;
                
                foreach (Group gp in gc)
                {
                    if (gp.Type == TGroupType.grpUsersWaitingMyAuthorization)
                    {
                        foreach (User user in gp.Users)
                        {
                            if (user.Handle.Equals(pUser.Handle))
                            {
                                user.BuddyStatus = TBuddyStatus.budPendingAuthorization;
                            }
                        }
                    }


After authorize request I checked all user handles from the hardwired group "grpUsersAuthorizedByMe" and I wondered because the requesting user was already authorized! The requesting user just didn't receive the positive authorizing. After a second request the client recognized it and the status image turned green.
After updating the client of requesting user from Skype version 3.6.x to 3.8 all worked fine. So, it seems to be a client version specific behaviour, maybe just a bug of this 3.6.x version I used, but I have tried many code combinations and didn't found a workaround for this 3.6.x version.
TheUberOverlord
Not sure if there was a bug in 3.6 or not with this, but glad you see it works.
Dr.O
Thanks a lot again for your help.
TheUberOverlord
QUOTE (Dr.O @ Fri Jun 6 2008, 03:56)
Go to the original post
Thanks a lot again for your help.


You are very welcome. Glad I could help smile.png
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.