I have a Wechat subscribe page, and I set up in https://admin.wechat.com/ a token as well as the webhook URL of my server myserver.com/wechat/webhook
My server Python code authenticates Wechat server with signature check, nonce and timestamp and I'm able to receive messages from Wechat to my webhook.
But I can't send messages from my server to Wechat, I'm using the following code and the token set in the admin console as previously, and following the previous docs:
http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages
# Parse the received WeChat message
message = xmltodict.parse(message)
content = message['xml']['Content']
fromUser = message['xml']['FromUserName']
toUser = message['xml']['ToUserName']
createdTime = message['xml']['CreateTime']
# reply to message
post_data = {
"touser": fromUser,
"msgtype": "text",
"text":
{
"content": "Thanks for your message"
}
}
api_url = 'https://api.wechat.com/cgi-bin/message/custom/send?access_token=' + token
response = requests.post(api_url, data=post_data)
content = response.content
This is the error that I'm getting:
{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: [udQ9ka0880vr32!]"}
What token am I supposed to use? Or what could be the error? Thanks
I think it might be a permission problem... In my Wechat page admin console, it says I have Permission obtained for Auto-reply, but not for Service API. Anyone can confirm this?
Indeed I tested successfully instantly replying to POST messages with an http response (Auto-reply or callback) http://admin.wechat.com/wiki/index.php?title=Callback_Messages
And the Service API seems to not be working (which was the purpose of my question) http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages
Related
I try to send webhook alerts to wunderbit (crypto trading platform), but i receive
<Response 403> error. Please help.
My code:
import requests
target_url= "https://wundertrading.com/bot/exchange"
message = "My open long command(generated by wunderbit)"
my_request = requests.get(target_url, data = message, headers = {"Content-Type": "text/plain"})
print(my_request)
were you trying to send a signal from a custom server?
Only signals from TradingView were allowed previously. Now you can send a custom signal, but you will need to whitelist your IP first. see WunderTrading documentation
I am using a single twilio number to trigger an sms being sent through a django function.
If a person accesses my app through my website then the app will parse sendphonenum from a post request from the website.
If a person accesses my app by sending sms to twilio number, it will parse sendphonenum from text message.
The problem occurs after Twilio has sent a message to sendphonenum.
If a message was triggered from the website it should redirect to dashboard page for user who sent message. But don't do this if message was triggered through an initial sms.
#csrf_exempt
def sms_response(request):
if request.method == "POST":
# parse sendphonenum from text message sent from mobile phone to twilio number +14545552222
# or parse sendphonenum from a post request from website
message_body = request.POST['Body']
sendnum_ary = re.findall('[0-9]+', message_body)
sendnum = "".join(sendnum_ary)
sendphonenum = "+1" + sendnum
mytwilionum = "+14545552222"
# put your own credentials here
ACCOUNT_SID = "123434234234"
AUTH_TOKEN = "abcsdasda"
client = Client(ACCOUNT_SID, AUTH_TOKEN)
client.messages.create(
to= sendphonenum,
from_= mytwilionum,
body='someone told me to message you'
)
## there is no platform variable, just doing some mock code to show you what I'd want to happen
## note sms_response function url must be same for both website and mobile phone, as both are using same webhook A MESSAGE COMES IN for +14545552222
if platform == 'web':
return HttpResponseRedirect(reverse('dashboard'))
return HttpResponse('')
Twilio developer evangelist here.
Twilio will send a bunch of headers along with the request which you could check for. For example, all requests are signed and include an X-Twilio-Signature header. So you can check the request.META dictionary for the existence of that header. To be extra sure it was a request from Twilio, you can verify that the signature is correct.
if ‘HTTP_X_TWILIO_SIGNATURE’ in request.META:
# An XML response with an empty `<Response/>` element
resp = MessagingResponse()
return HttpResponse(str(resp))
else:
return HttpResponseRedirect(reverse('dashboard'))
Let me know if that helps at all.
While requesting http://www.sonyliv.com/api/v2/vod/search API, I am getting "Invalid csrf token" message in chrome postman.
{
"code": "403",
"name": "Bad Request",
"message": "Invalid csrf token"
}
When I look to Chrome Inspect Element > Network tab in Headers section, I found
"X-XSRF-TOKEN:tGXcHOmy-ro-GQfTestDSAp8EINq85dwHpdU"
as a token but this token is changed in every session, how can i pass X-XSRF-TOKEN value in my request to get the required result.
Please Help.
The idea of the CSRF tokens is that you can't call an API service if you're not doing it from the expected form, that's why it always changes its value.
I'm guessing you're trying to use that API not officially... so what you could try is to GET the base website and store in a cookie jar all the cookies it sends you and then try to query the search endpoint.
That way your request will include the XSRF token and the rest of the cookies and hopefully the server will think you request is legit.
Hope it helps
I'm building a chatbot for fun and I cannot send messages to the following API: https://webchat.botframework.com/api/conversations.
After a webchat user send a message, I know the conversation Id and Sender ID. In order to reply, I do the following steps:
First, I retrieve the token with the following code:
response = requests.post(
"https://webchat.botframework.com/api/tokens/conversation",
headers={"Authorization": "BotConnector " + pwdChat,"Content-Type": "application/json"})
data = response.json()
token = data
Then, I would like to send a message to the webchat user with he following code:
requests.post('https://webchat.botframework.com/api/conversations/' + sendersk2 + '/messages/',
headers={"Authorization": "Botconnector " + token, "Content-Type": "application/json"},
json={
"type": "message",
"text": "Hi!"
})
But, I receive an Response [403] error labelled as : "BadArgument:Security token not valid for this conversation"
Any idea of the issue?
There are a couple things that might help.
The endpoint you're using brings back a complex JSON object and you'll need to extract the token property from that.
Alternatively, you can use https://webchat.botframework.com/api/tokens instead, but you'll also need to trim quotes off the end.
Basically, look at the response from your token POST request and ensure you're pulling the token out properly.
Additionally it looks like you are talking to the V1 endpoints. We no longer actively support V1. Please consider upgrading to V3. Thanks.
I am trying to develop a app which will post on user's Facebook page.
Steps I followed are:
1.Created a fb App, with permission : manage_pages and publish_actions
2.Redirected user to 'https://www.facebook.com/dialog/oauth
With parameters:
client_id=FACEBOOK_APP_ID
redirect_uri=FACEBOOK_REDIRECT_URL
scope=manage_pages,publish_actions
Where user allowed app against each permissions
3.On call back url (FACEBOOK_REDIRECT_URL), cought CODE sent by facebook api
4.Now I sent get request to url = https://graph.facebook.com/oauth/access_token with parameters:
'client_id':FACEBOOK_APP_ID
'redirect_uri':FACEBOOK_REDIRECT_URL
'client_secret':FACEBOOK_SECRET_KEY,
'code':CODE
from respose sent by facebook, I filtered TOKEN
5.sent get request to url = https://graph.facebook.com/me/accounts. with parameters:
'access_token':TOKEN
from response I received, I saved page id as PAGE_ID, page_token as PAGE_TOKEN
6.I tried to post something on user's facebook page, I sent post request to url = https://graph.facebook.com/PAGE_ID/feed , with parameters:
'access_token':TOKEN'
'message': MESSAGE_TEXT,
Snap! in response I received:
{
"error": {
"message": "(#200) The user hasn't authorized the application to perform this action",
"type": "OAuthException",
"code": 200
}
}
I couldn't figure out What mistake I am committing, Do I need to get my app reviewed before posting ? If yes, How can I test my app?
I also tried this by creating a test user. I got the same error.
Thanks to #dhana,
In order to Post on a facebook page, App need manage_pages and publish_action app centre permission, and manage_pages , publish_action and status_update scope while requesting
url = https://www.facebook.com/dialog/oauth?\
client_id='+FACEBOOK_APP_ID+'&\
redirect_uri=' +FACEBOOK_REDIRECT_URL+'&\
scope=manage_pages,publish_actions,status_update