Get tweet from especific user from tweet

时间:2016-10-20 19:49:09

标签: azure twitter

I am trying to replicate an example in which explain how to receive information from twitter, through azure.

the example is as follows example link

The code used in the example is:

runbook

    param (
 [object]$WebhookData
 )

if ($WebhookData -ne $null) 
    {
        $BodyContent = $WebhookData.RequestBody
        Write-Output "There was a tweet from $BodyContent"
    }
else
    {
        Write-Error "Something went wrong buddy"   
    }

webhook

$Credential = Get-Credential

#Authenticate to Azure and AzureRM
Add-AzureAccount -Credential $Credential | Out-Null
Add-AzureRmAccount -Credential $Credential | Out-Null

#Provide the necessary information for your environment
$Webhook = New-AzureRmAutomationWebhook `
 -Name "TriggeredByTwitter"`
 -RunbookName "Hello-Twitter"`
 -IsEnabled 1 `
 -ExpiryTime (Get-Date).AddDays(10)`
 -ResourceGroupName "Automation"`
 -AutomationAccountName "AutomationAccount"

#Print the webhook uri
Write-Host $Webhook.WebhookUri -ForegroundColor Green

At the time of creating a webhook, applying a variable, but I think this is where the problem lies.

I would like to know how to use a variable that allows me, and that type must be to work.

1 个答案:

答案 0 :(得分:1)

我测试了指令,它们似乎有效。我做的是:

创建自动化帐户,Runbook并向Runbook添加一些内容

1)登录https://portal.azure.com

2)添加新的自动化帐户。等到它完成。

Create Automation Account

3)在自动化帐户

中创建一个新的PowerShell Runbook

Create a runrook

4)准备就绪后,在Azure门户内导航到它并编辑其内容。添加其内容

Write-Host "Hello World!"

4)保存&发布Runbook。

5)在Runbook中,打开"测试窗格"

Save, publish and start the runbook

6)按"开始"它应该打印出#Hello; Hello World!"。

Running the Hello world runbook

创建webhook

7)返回Runbook并按下" Webhook"按钮。

8)按"添加webhook"按钮添加新的webhook

9)给webhook一个名字并保留其余的设置。它们非常适合测试:)在按OK之前,请记下它为您呈现的URL。按OK。

10)按创建。

New webhook

测试webhook

11)返回Runbook,进行更多编辑,然后转到"测试窗格"

12)打开,例如Chrome扩展程序Postman或导航至https://www.hurl.it并测试webhook。

13)在创建webhook时,向您提供的URL发出POST请求。

enter image description here

14)返回自动化帐户并观察监控部分。应该很快会出现一个请求。当您打开最新请求时,您可以看到它的输出

将数据传递到webhook

15)修改脚本以阅读

Param
(
    [object] $webhookdata
)

Write-Output "Hello World! - $($webhookdata.RequestBody)"

保存并发布脚本

16)回到hurl.it并在请求中添加一些正文。

POST with body

17)现在回到监控部分,您应该能够看到结果

Webhook with a body

18)如果您查看传递给脚本的数据。您还可以阅读其他参数

{"WebhookName":"testwh","RequestBody":"Test","RequestHeader":{"Accept":"*/*","Accept-Encoding":"gzip","Host":"s9events.azure-automation.net","User-Agent":"runscope/0.1","x-ms-request-id":"3955cc96-34c5-409b-94c5-19ec37e07c49"}}