Ejemplo n.º 1
0
 /**
  * @param Request $request
  * @return \BladeView|bool|\Illuminate\View\View|mixed|\Symfony\Component\HttpFoundation\Response
  */
 public function addFacebookAccount(Request $request)
 {
     $util = new Util();
     $userService = new userService();
     $accessToken = $request->input('accessToken', '');
     $result['ok'] = 0;
     $result['accessToken'] = $accessToken;
     try {
         $user = Auth::user();
         $facebook = $util->initFacebook();
         // OAuth 2.0 client handler
         $oAuth2Client = $facebook->getOAuth2Client();
         // Exchanges a short-lived access token for a long-lived one
         $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
         $facebook->setDefaultAccessToken($longLivedAccessToken);
         $profile = $facebook->getProfile();
         $result = $userService->createBusinessSocialAccount($profile, $longLivedAccessToken, $user);
     } catch (\Facebook\Exceptions\FacebookResponseException $e) {
         if ($request->ajax()) {
             $result['error_message'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e->getMessage()]);
         }
     }
     return response()->json($result);
 }
Ejemplo n.º 2
0
 public function postToSocial($socialPostId, $userId, $social, $images, $descPost)
 {
     $util = new Util();
     $socialPostModel = new socialPostModel();
     $socialGalleryPostModel = new socialGalleryPostModel();
     $userBusinessSocial = new userBusinessSocialModel();
     if (!$this->isValidSocial($userId, $social->type, $social->socialId)) {
         throw new \Exception('BAD Social ID');
     }
     $socialAccount = $userBusinessSocial->getItem($userId, $social->type, $social->socialId);
     $facebook = $util->initFacebook();
     $facebook->setDefaultAccessToken($socialAccount->token);
     $arrayFbMedia = [];
     foreach ($images as $image) {
         $imagePost = $facebook->postPhoto($image->url, $image->caption);
         $socialGalleryPostModel->updateItem($image->socialGalleryPostId, ['ref' => $imagePost['id']]);
         array_push($arrayFbMedia, $imagePost);
     }
     $socialPost = $facebook->postFeed($arrayFbMedia, $descPost);
     $socialPostModel->updateItem($socialPostId, ['ref' => $socialPost['id']]);
     return $socialPost;
 }
Ejemplo n.º 3
0
 public function postProductToFacebook($productId, $descPost, $images, $userId)
 {
     $productModel = new productModel();
     $userSocialModel = new userSocialModel();
     $util = new Util();
     $socialAccount = $userSocialModel->getItem($userId, KACANA_SOCIAL_TYPE_FACEBOOK);
     $facebook = $util->initFacebook();
     $facebook->setDefaultAccessToken($socialAccount->token);
     $product = $productModel->getProductById($productId);
     if (!$product) {
         throw new \Exception('BAD Product ID');
     }
     $galleries = $product->galleries;
     $arrayFbMedia = [];
     foreach ($galleries as $gallery) {
         if (in_array($gallery->id, $images)) {
             array_push($arrayFbMedia, $facebook->postPhoto('http:' . AWS_CDN_URL . str_replace(' ', '%20', $gallery->getOriginal('image')), $product->name));
         }
     }
     return $facebook->postFeed($arrayFbMedia, $descPost);
 }