public function post($settings, $org) { $apiId = $settings['registry_info'][0]['publisher_id']; $twitter = ""; if ($org->twitter != "") { $twitter = $org->twitter; if (substr($twitter, 0, 1) != '@') { $twitter = '@' . $twitter; } $twitter = ' ' . $twitter; } $status = $org->name . $twitter . " has published their #IATIData. View the data here: "; $status .= 'http://iatiregistry.org/publisher/' . $apiId . ' #AidStream'; try { $twitterResponse = Twitter::postTweet(['status' => $status, 'format' => 'json']); $this->logger->info(sprintf('Twitter has been successfully publish for %s with info : %s', $org->name, $twitterResponse)); } catch (\Exception $e) { $this->logger->error($e, ['org_name' => $org->name]); } }
/** * Execute the job. * @return void */ public function handle() { if (env('APP_ENV') !== 'production') { Log::info(sprintf('this env is %s. tweet not publish.', env('APP_ENV'))); return; } if (starts_with($this->article->name, 'test')) { Log::info('this article is test. tweet not publish.'); return; } $body = "{$this->article->name} \n {$this->article->title} \n {$this->article->body}"; if (self::MAX_LENGTH - 30 < mb_strlen($body)) { $body = mb_substr($body, 0, self::MAX_LENGTH - 30) . '…'; } $body .= "\n" . env('SITE_URL'); Log::info("tweet publish id:{$this->article->id}"); try { Twitter::postTweet(['status' => $body, 'format' => 'json']); Log::info("tweet complete. id:{$this->article->id}"); } catch (\Exception $e) { Log::error("tweet error. id:{$this->article->id}, message:{$e->getMessage()}, body_count:" . mb_strlen($body)); } }
public function setStateAttribute($value) { if (isset($this->attributes[Production::ATTR_STATE])) { //Publicacion en redes sociales if ($this->attributes[Production::ATTR_STATE] == Production::STATE_PROGRAMMED && $value == Production::STATE_ACTIVE) { //PUBLICA EN LA PAGINA DE FACEBOOK LA NUEVA PRODUCCION AGREGADA $page_id = "974813252592135"; $post_url = 'https://graph.facebook.com/' . $page_id . '/feed'; $page_access_token = 'CAAMlvU2gRHsBAPt2mZBymHkjZChELemLYpyRjMDp6VqjscjB3VwUbGfQsdyuFfNqpFaXZCnvL6ngWorbg6q2V6FP4rrcIUB5dgisdVSr4STFTzecD2zRoOCYFZCei1D6zxNEm0zHZCXr7DFtbMPTIVSioR1sitpGqcV1aTFgZBadL1CVlmbeMk'; $data['access_token'] = $page_access_token; $data['link'] = url("production/" . $this->attributes[Production::ATTR_SLUG]); $data['message'] = "¡Hemos agregado recientemente \"" . $this->attributes[Production::ATTR_TITLE] . "\", desde ya puedes disfrutarla online y gratis!"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $post_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); curl_close($ch); //PUBLIC EN TWITTER $url = $this->attributes[Production::ATTR_IMAGE]; $path = public_path("assets/db/images/" . Util::fileExtractName($url) . "." . Util::fileExtractExtension($url)); $uploaded_media = Twitter::uploadMedia(['media' => File::get($path)]); @Twitter::postTweet(['status' => "Hemos agregado \"" . $this->attributes[Production::ATTR_TITLE] . "\" ¡Disfrutalo desde ya!", 'media_ids' => $uploaded_media->media_id_string]); } } $this->attributes[Production::ATTR_STATE] = $value; }
/** * Handle the event. * * @param UserBecomeSponsor $event * @return void */ public function handle(UserBecomeSponsor $event) { Twitter::postTweet(['status' => 'Many thanks to , "' . $event->user->username . '" for sponsoring!! - https://laramap.com/@' . $event->user->username . ' #laramap #sponsor', 'format' => 'json']); }
/** * Handle the event. * * @param UserRegistered $event * @return void */ public function handle(UserRegistered $event) { Twitter::postTweet(['status' => 'Welcome, "' . $event->user->username . '"" on Laramap! - https://laramap.com/@' . $event->user->username . ' #laramap #artisan', 'format' => 'json']); }
/** * Handle the event. * * @param PostWasTweeted $event * @return void */ public function handle(PostWasTweeted $event) { if (env('APP_ENV') == 'production') { Twitter::postTweet(['status' => "New Post '{$event->post['attributes']['title']}' at http://markrailton.com/blog/{$event->post['attributes']['slug']}", 'format' => 'json']); } }