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 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配