duange2971 2015-10-31 03:59
浏览 62
已采纳

使用API​​在Twitter上发布到多个帐户。 获取重复状态错误。

Trying to post to twitter using laravel and this twitter API package. Im using a foreach loop to grab each of the account tokens and post but I keep getting the error Duplicate status because it seems like its not changing the tokens before its posting to twitter. I've tried to refresh the page and the break the connection, still getting the error.

here is my foreachloop

foreach ($post['accountsToPost'] as $accountToPost) {
            $uniqueProfile= DB::table('profiles')->where('social_media_id', $accountsToPost)->first();
            $new_token = [
                'oauth_token'        => $uniqueProfile_test->oauth_token,
                'oauth_token_secret' => $uniqueProfile_test->oauth_secret,
                'x_auth_expires'     => $uniqueProfile_test->x_auth_expires,
            ];

            Session::forget('access_token');
            Session::put('access_token', $new_token);
            Twitter::postTweet(['status' => $post['post_text'], 'format' => 'json']);
            Session::flash('flash_message', 'Success! Your post has been sent.');
        }

Into the foreach loop im passing in 1. The social media I.D 2. The Oauth, secret tokens 3. The content to post

When I track the tokens using echo it seems to be getting all the right tokens but just not when posting to twitter. Could it be a connection issue? thats its not refreshing the connection for each account?

  • 写回答

1条回答 默认 最新

  • drl47263 2015-10-31 09:24
    关注

    Figured it out. For anyone else that has the same problem with the package. Don't use session:: commands in the foreach loop. Use the Twitter::reconfig method. Not sure why but on post the session wasn't changing the tokens while in the foreach loop no matter what I tried. Using the reconfig method solved all the token issues.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?