Ejemplo n.º 1
0
 public function send()
 {
     $content = $this->_content;
     $status = $this->_status;
     $response = new \Symfony\Component\HttpFoundation\JsonResponse($content, $status);
     $response->send();
 }
Ejemplo n.º 2
0
/**
 * Sends a response as json with a status code.
 *
 * @param array $data
 * @param int $status
 */
function respondJson($data = [], $status = HTTP_OK)
{
    $encoded = utf8_encode_array($data);
    $response = new Symfony\Component\HttpFoundation\JsonResponse($encoded, $status);
    $response->setEncodingOptions(JSON_NUMERIC_CHECK);
    $response->send();
}
Ejemplo n.º 3
0
    $name = $helper->convertBase64ToTmpFile($photo);
    $url = $request->getScheme() . '://' . $request->getHost() . '/share/' . $name;
    $response = new \Symfony\Component\HttpFoundation\JsonResponse(['url' => $url]);
    $response->send();
});
$app->post('/authTwitter', function () {
    session_start();
    $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
    $_SESSION['image'] = $request->request->get('photo');
    $_SESSION['text'] = $request->request->get('text');
    $connection = new \Abraham\TwitterOAuth\TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
    $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => TWITTER_OAUTH_ENDPOINT));
    $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
    $authURL = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
    $response = new \Symfony\Component\HttpFoundation\JsonResponse(['url' => $authURL]);
    $response->send();
});
$app->get('/shareTwitter', function () {
    session_start();
    $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
    $_SESSION['oauth_token'] = $request->query->get('oauth_token');
    $_SESSION['oauth_verifier'] = $request->query->get('oauth_verifier');
    $connection = new \Abraham\TwitterOAuth\TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_SESSION['oauth_verifier']));
    $_SESSION['oauth_token'] = $access_token['oauth_token'];
    $_SESSION['oauth_token_secret'] = $access_token['oauth_token_secret'];
    $_SESSION['twitter_user_id'] = $access_token['user_id'];
    $connection = new \Abraham\TwitterOAuth\TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $imageURL = $_SESSION['image'];
    $photo = $connection->upload('media/upload', ['media' => $imageURL]);
    $statues = $connection->post("statuses/update", ['status' => $_SESSION['text'], 'media_ids' => $photo->media_id]);