steampy icon indicating copy to clipboard operation
steampy copied to clipboard

Methods for adding and removing friends from friend list

Open Albert-Bruun-Thomsen opened this issue 1 year ago • 4 comments

Methods for adding and removing friends from friend list

Albert-Bruun-Thomsen avatar Sep 27 '23 10:09 Albert-Bruun-Thomsen

Hello! I'm not a programmer, but this works: def friend_add(self, steamid: str) -> dict: url = 'https://steamcommunity.com/actions/AddFriendAjax' data = f"sessionID={self._get_session_id()}&steamid={steamid}&accept_invite=0" headers = { "Host": "steamcommunity.com", "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0", "Accept": "/", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate, br", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With": "XMLHttpRequest", "Content-Length": str(len(str(data))), "Origin": "https://steamcommunity.com", "Connection": "keep-alive", #"Cookie": "".join(f"{cookie.key}={cookie.value}; " # for key, cookie in self.session.cookie_jar.filter_cookies(self.StoreURL).items())[:-2], "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "Sec-GPC": "1" } response = self._session.post(url, data=data,headers=headers).json() return response def friend_remove(self, steamid: str) -> dict: url = 'https://steamcommunity.com/actions/RemoveFriendAjax' data = f"sessionID={self._get_session_id()}&steamid={steamid}&accept_invite=0" headers = { "Host": "steamcommunity.com", "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0", "Accept": "/", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate, br", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With": "XMLHttpRequest", "Content-Length": str(len(str(data))), "Origin": "https://steamcommunity.com", "Connection": "keep-alive", #"Cookie": "".join(f"{cookie.key}={cookie.value}; " # for key, cookie in self.session.cookie_jar.filter_cookies(self.StoreURL).items())[:-2], "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "Sec-GPC": "1" } response = self._session.post(url, data=data,headers=headers).json() return response

Suxoran avatar Oct 02 '23 16:10 Suxoran

Does AddFriendAjax still work? I tried the same method as above, but it doesn't work for me.

Hodackin avatar Feb 14 '24 09:02 Hodackin

This feature works for me, this is how I added this method to client.py. You can send the response received from this function.

Suxoran avatar Feb 14 '24 10:02 Suxoran

Yeah, ur implementation work for me. Ааfter some research, can say that the data for this methods must be passed in the body of request (not like query parameters), also Content-Type header required.

Hodackin avatar Feb 14 '24 13:02 Hodackin