通过curl发布到twitter

时间:2013-03-27 08:29:03

标签: php curl

我必须允许客户在我正在构建的博客上发布文章,并在twitter,facebook和linkedin上自动发布帖子。 我无法为客户创建应用程序facebook / twitter,甚至无法给我密码。 所以我想用curl(或其他方法)从php创建一个帖子。 我找到了这个: http://www.flameweb.net/using_php_to_update_twitter 我输入了用户名和密码,运行代码并返回“成功”,但Twitter上没有帖子。 为什么呢?

2 个答案:

答案 0 :(得分:2)

这是来自a script360percents.com的修改版本。它使用移动Twitter。当我使用它时,它工作,我现在没有检查。

Signin.sh:

#!/bin/bash

#REQUIRED PARAMS
username=$1
password=$2
cookie="$username.cookie"

#EXTRA OPTIONS
uagent="Mozilla/5.0"
#proxy="--socks5 127.0.0.1:9050"

#INITIAL PAGE
initpage=`curl $proxy -s -b $cookie -c $cookie -L --sslv3 -A "$uagent" "https://mobile.twitter.com/session/new"`
token=`echo "$initpage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//' | tail -n 1`

#LOGIN
loginpage=`curl $proxy -s -b $cookie -c $cookie -L --sslv3 -A "$uagent" -d "authenticity_token=$token&username=$username&password=$password" "https://mobile.twitter.com/session"`

Tweet.sh:

#!/bin/bash

#REQUIRED PARAMS
username=$1
password="$2"
tweet=$3
cookie="$username.cookie"

#EXTRA OPTIONS
uagent="Mozilla/5.0"
#proxy="--socks5 127.0.0.1:9050"

#HOME PAGE
homepage=`curl $proxy -s -b $cookie -c $cookie -L -A "$uagent" "http://mobile.twitter.com/"`
if [ "$homepage" != "${homepage/Sign in/}" ]; then
    echo "Signing $username in"
    ./signin.sh $username $password
fi

echo "Tweeting $tweet by $username"

#TWEET
tweettoken=`echo "$homepage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//' | tail -n 1`
update=`curl $proxy -s -b $cookie -c $cookie -L -A "$uagent" -d "authenticity_token=$tweettoken&tweet[text]=$tweet&tweet[display_coordinates]=false" "http://mobile.twitter.com/"`

答案 1 :(得分:0)

您是否尝试过使用Twitter API?

REST API v1.1

相关问题