/** * Creates a new Fbposts model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Fbposts(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Grab the user's ungrabbed posts from Facebook * * @param \yii\authclient\BaseOAuth $client */ public static function grabSocial(\yii\authclient\BaseOAuth $client) { if ($client->getId() === 'facebook') { $token = $client->getAccessToken(); \Facebook\FacebookSession::enableAppSecretProof(false); $session = new \Facebook\FacebookSession($token->getToken()); $request = new \Facebook\FacebookRequest($session, 'GET', "/me/posts"); $response = $request->execute()->getResponse(); $posts = $response->data; foreach ($posts as $post) { if (!Fbposts::find()->where('post_id = :pid', ['pid' => $post->id])->exists()) { $fbpost = new Fbposts(['user_id' => Yii::$app->user->id, 'post_id' => $post->id, 'message' => isset($post->message) ? $post->message : $post->story, 'created_time' => $post->created_time]); $fbpost->save(); } } } }