M
M
Misha Titkov2017-02-07 20:42:45
Classmates
Misha Titkov, 2017-02-07 20:42:45

API OK MediaPost problem with symbols +, &, #, %?

I write symbols in the request body, and it gives errors
{"error_code":3,"error_msg":"METHOD : Method can not be null","error_data":null}
{"error_code":104,"error_msg":"PARAM_SIGNATURE : Invalid signature feecb27fe2c3422aed4d5967f0b5d7e3, calculated by string application_key=CBAKAMHLEBABABABAattachment={ \"media\": [ { \"type\": \"text\", \"text\": \" in Prague, only with official documents. Cooking for the head chef, for the menu - not only helped, but also cooked more fully. Dosvid є obov'yazkovim. Payment 120 Korun/year. B0 607 407 092, [email protected]\" } ]}format=jsongid=53327505719498method=mediatopic.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tom Nolane, 2017-02-07
@Zusy

are you encrypting the signature with an MD5 hash?
the request body uses attachment, before sending, all attachment characters must be encoded in url format
on php
on js
in c#
where attachment - your attachment before encoding
encode_attachment - attachment after encoding in url
and encode_attachment already sent to MediaPost
in c# looks like this (works)

h0 = "application_key=" + OK.APPK + "attachment=" + attachments + "format=jsongid=" + gid + "method=mediatopic.posttype=GROUP_THEME" + OK.SSK;
                g = GetMD5Hash(string.Format("{0}", h0));
                attachments = HttpUtility.UrlEncode(attachments);
                request_path = "https://api.ok.ru/fb.do?application_key=" + OK.APPK + "&attachment=" + attachments + "&format=json&gid=" + gid + "&method=mediatopic.post&type=GROUP_THEME&sig=" + g + "&access_token=" + OK.AccessToken;
                string req = Response(request_path, sender);

ps in the signature, you need to use attachment before encoding, and in the request itself, attachment is encoded
p.s.s. there are some encoders (for example, in C#...) that do not process all characters
. MD5
for js ( poke )
for php $hash = md5($str);
for c#
public static string GetMD5Hash(string input)
        {
             var x = new System.Security.Cryptography.MD5CryptoServiceProvider();
             var bs = Encoding.UTF8.GetBytes(input);
             bs = x.ComputeHash(bs);
             var s = new StringBuilder();
             foreach (var b in bs)
             {
                s.Append(b.ToString("x2").ToLower());
             }
             return s.ToString();
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question