yowsup icon indicating copy to clipboard operation
yowsup copied to clipboard

method "profile_setPicture"

Open Marcorele opened this issue 12 years ago • 12 comments

Hello,

i try change my profil picture using method : profile_setPicture(str filePath)

my code :

methodsInterface.call("profile_setPicture",("pic.jpg"))

i have an error message : TypeError: sendSetProfilePicture() takes exactly 2 arguments (9 given)

What is wrong? thx you

Marcorele avatar Jun 03 '14 16:06 Marcorele

Someone can help me please..

Marcorele avatar Jun 04 '14 16:06 Marcorele

@Marcorele

Try this:

Be sure, that the file exists in the same folder where you have the script

y = YowsupConnectionManager()

methodsInterface = y.getMethodsInterface()
methodsInterface.call("profile_setPicture", "pic.jpg")

mgp25 avatar Jun 05 '14 09:06 mgp25

Thank you so much for the help!

But i think the problem is the syntax of the method...missing some arguments...i dont know

Marcorele avatar Jun 05 '14 09:06 Marcorele

@Marcorele here is what you can find in connectionmanager.py about that method. Try what i told you in the other comment, and if its not working, post your script and the error it gives you.

 self.methodInterface.registerCallback("profile_setPicture", self.sendSetProfilePicture)

...

def sendSetProfilePicture(self, filepath):
    return self.sendSetPicture(self.jid, filepath)

def sendSetPicture(self, jid, imagePath):
    f = open(imagePath, 'r')
    imageData = f.read()
    imageData = bytearray(imageData)
    f.close()
    idx = self.makeId("set_picture_")
    self.readerThread.requests[idx] = self.readerThread.parseSetPicture
    listNode = ProtocolTreeNode("picture",{"xmlns":"w:profile:picture","type":"image"}, None, imageData)
    iqNode = ProtocolTreeNode("iq",{"id":idx,"to":jid,"type":"set"},[listNode])
    self._writeNode(iqNode)

mgp25 avatar Jun 05 '14 09:06 mgp25

i saw the code in connectionmanager.py, i don't understand the 2 methods (sendSetProfilePicture and sendSetPicture); one just need the filepath, other ne need jid and filepath

The picture is on the same folder than the script; the error message is: TypeError: sendSetProfilePicture() takes exactly 2 arguments (9 given)

Marcorele avatar Jun 05 '14 09:06 Marcorele

Full profilepic.py Make sure u u call it with correct parameters

import os
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.sys.path.insert(0,parentdir)
import time

from Yowsup.connectionmanager import YowsupConnectionManager

class WhatsappProfileClient:

    def __init__(self, filePath):

        self.filePath = filePath
        #self.jid = 19786313218
        #self.jid  = 19792272005
        connectionManager = YowsupConnectionManager()
        self.signalsInterface = connectionManager.getSignalsInterface()
        self.methodsInterface = connectionManager.getMethodsInterface()

        self.signalsInterface.registerListener("auth_success", self.onAuthSuccess)
        self.signalsInterface.registerListener("auth_fail", self.onAuthFailed)

        #self.signalsInterface.registerListener("disconnected", self.onDisconnected)

        #self.interfaceHandler.registerListener("profile_setPictureSuccess", self.onSetProfilePicture)
        #self.interfaceHandler.registerListener("profile_setPictureError", self.onSetProfilePictureError)

        self.done = False

    def login(self, username, password):
        self.username = username
        self.methodsInterface.call("auth_login", (username, password))

        while not self.done:
            time.sleep(0.5)

    def onAuthSuccess(self, username):
        print("Authed %s" % username)       
        time.sleep(1)
        #self.methodsInterface.call("group_setPicture", (self.jid, self.filePath))
        self.methodsInterface.call("profile_setPicture", (self.filePath,))
        #self.methodsInterface.call("profile_setPicture", (r"F:\1.jpg",))
        #self.methodsInterface.call("profile_setPicture", (self.filePath))
        print("Set profile image")
        self.done = True

    def onAuthFailed(self, username, err):
        print("Auth Failed!")
        self.done = True

    def onDisconnected(self, reason):
        print("Disconnected because %s" %reason)

mrtass avatar Jun 05 '14 09:06 mrtass

There you go @Marcorele ! Thanks @mrtass

@Marcorele the sendSetProfilePicture only returns your jid and the path. Jid is the whatsapp acount, an example:

[email protected]

Where the first numbers is the country code, in the example 34 is the country code, and the followed by your number.

The other method, reads the image and request set the profile picture.

mgp25 avatar Jun 05 '14 09:06 mgp25

Also remember on iPhone profile pic will not appear if contact is not saved in address book On Android picture will appear but will not update if conversation window is already open unless u save the contact in address book or manual maximize the photo

mrtass avatar Jun 05 '14 09:06 mrtass

Thank you so much @mgp25 y @mrtass !!! I will try it and keep you informed

Marcorele avatar Jun 05 '14 19:06 Marcorele

It work perfectly with :

methodsInterface.call("profile_setPicture",("pic.jpg",))

The problem was the , missing after the "pic.jpg"

In fact, i don't understand why need the ,

PS: need presence_sendAvailable to update the picture faster on the profile

Thank you guys!

Marcorele avatar Jun 06 '14 14:06 Marcorele

@Marcorele Nice ;) dont forget to close the issue.

mgp25 avatar Jun 06 '14 14:06 mgp25

@Marcorele As sed in https://github.com/tgalal/yowsup/wiki/%5BLegacy%5D-Yowsup-Documentation#methods You should put "," after single parameters. Otherwise python will parse them as individual chars

PoMkaNik avatar Sep 30 '15 08:09 PoMkaNik