我必须允许客户在我正在构建的博客上发布文章,并在 twitter、facebook 和linkedin 上自动发布帖子。我无法为客户创建应用程序 facebook / twitter 甚至给我密码。所以我想使用 curl (或其他方法)从 php 创建一个帖子。我发现了这个: http ://www.flameweb.net/using_php_to_update_twitter 我输入了我的用户名和密码,运行代码,它返回“成功”,但 twitter 上没有帖子。为什么?
问问题
1552 次
2 回答
2
这是来自360percents.com的脚本的修改版本。它使用移动推特。我用的时候有用,现在没查。
登录.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"`
推文.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/"`
于 2013-03-27T08:41:30.317 回答
0
您是否尝试过使用 Twitter API?
于 2013-03-27T09:59:15.787 回答