【问题标题】:Post to twitter via curl通过 curl 发布到 Twitter
【发布时间】:2013-03-27 17:59:15
【问题描述】:

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

【问题讨论】:

    标签: php curl


    【解决方案1】:

    这是 a script 的修改版本,来自 360percents.com。它使用移动推特。用的时候有效,现在没查。

    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/"`
    

    【讨论】:

      【解决方案2】:

      您是否尝试过使用 Twitter API?

      REST API v1.1

      【讨论】:

        猜你喜欢
        • 2013-01-23
        • 1970-01-01
        • 2012-11-08
        • 1970-01-01
        • 1970-01-01
        • 2013-11-12
        • 2015-07-26
        • 2012-09-13
        • 1970-01-01
        相关资源
        最近更新 更多