mgp25 / psn-api

PlayStation Network API in python
131 stars 26 forks source link

Messages #11

Open frasza opened 6 years ago

frasza commented 6 years ago

Hey!

Looking for PSN Messaging API solution and I found your API but I am wondering, are you working on messaging part of API? :)

mgp25 commented 6 years ago

Hello @frasza,

Yes, that is something I was working on, but haven't had time to work on it lately. PSN Messaging now uses HTTP2.0, and this is what it looks like:

:method: POST
:path: /groupMessaging/v1/messageGroups/~xxxE837DyyyB2E5C.7F6zzz27ED000ECA/messages
:authority: es-gmsg.np.community.playstation.net
:scheme: https
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0
accept: */*
accept-language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
accept-encoding: gzip, deflate, br
content-type: multipart/mixed; boundary="---------------------------26061"
authorization: Bearer 15e000c-36p0-400a-8b53-e94e0009745f
content-length: 204
origin: https://my.playstation.com
dnt: 1

-----------------------------26061
Content-Type: application/json; charset=utf-8
Content-Description: message

{"message":{"messageKind":1,"body":"que tal?"}}
-----------------------------26061--

None of the python libs were supporting http2, unless hyper. I have opened an issue there https://github.com/Lukasa/hyper/issues/380#issue-317301294 where I asked if I was doing it right:

        boundary = "---------------------------"+str(random.sample(range(10000, 99999), 1)[0])

        header = {
            'origin': 'https://my.playstation.com',
            'Authorization': 'Bearer ' + self.oauth,
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0',
            'Content-Type': 'multipart/mixed; boundary='+boundary,
            'accept-encoding': 'gzip, deflate, br',
            'accept': '*/*',
            'dnt': '1',

        }

        message_body = {
            "message": {
                "messageKind": 1,
                "body": message_text
            }
        }

        message = "\r\n"
        message += boundary+"\r\n"
        message += "Content-Type: application/json; charset=utf-8\r\n"
        message += "Content-Description: message\r\n"
        message += "\r\n"
        message += json.dumps(message_body) + "\r\n"
        message += boundary + "--\r\n"

        conn = HTTP20Connection("es-gmsg.np.community.playstation.net:443")
        request = conn.request('POST', "/groupMessaging/v1/messageGroups/"+thread_id+"/messages", headers=header, body=message)
        response = conn.get_response(request)
        print(response.read())

And the response I get from the code above is:

{"error":{"code":2121729,"message":"Bad request"}}

I think the function I posted above is right, but maybe it needs to be tweaked a bit yet.

Regards

isFakeAccount commented 3 years ago

Hi! Is there any progress on this? I could use the feature of sending messages. Thanks!