2015-11-27 10 views
8

मैं उसकेोकू पर एक सिम्फनी 2 ऐप का उपयोग कर रहा हूं और मैं अपने एपीआई से कनेक्ट नहीं कर सकता। एक रूप heroku पर cURL टाइमआउट

  • जब मैं सही ढंग से मेरे एप्लिकेशन में लॉग ऑन कर रहा हूँ, एक घटना श्रोता
  • शुरू हो रहा है मैं URL तक पहुँचने के माध्यम से

    1. मैं मुझे मेरी अनुप्रयोग में कनेक्ट:

      मैं तुम्हें परिदृश्य समझाने जो मुझे API टोकन वितरित करती है और मैं (अनुप्रयोग के लिए और एपीआई के लिए) उपयोगकर्ता एप्लिकेशन के मुखपृष्ठ पर उपयोगकर्ता सत्र में उन प्रमाणिकता को सहेजने

    2. मैं जुड़ा अनुप्रेषित

    तो मेरी समस्या बिंदु 3 पर है। मैंने यूआरएल तक पहुंचने के लिए curl और file_get_contents के साथ प्रयास किया और दोनों काम नहीं कर रहे हैं।

    जब मैं यूआरएल तक पहुंचने का प्रयास करता हूं जो मुझे मेरे एपीआई तक पहुंचने के लिए आवश्यक ओथ टोकन प्रदान करता है, तो यह विफल हो जाता है। मैंने ब्राउज़र (या पोस्टमैन) में मैन्युअल रूप से इस यूआरएल तक पहुंचने की कोशिश की और यह ओथ टोकन को अच्छी तरह से लौटाता है।

    घटना श्रोता:

     // Call of the url to deliver the token 
         $clientAPI = $this->em->getRepository('BgAPIBundle:Client')->findOneBy(array('providerAccess' => 'pcv')); 
         $curl = curl_init(); 
         curl_setopt($curl, CURLOPT_URL, urldecode($this->router->generate('fos_oauth_server_token', array('grant_type' => 'http://www.myapp/api/grants/api_key', 'client_id' => $clientAPI->getId() . '_' . $clientAPI->getRandomId(), 'client_secret' => $clientAPI->getSecret(), 'api_key' => $event->getAuthenticationToken()->getUser()->getApiKey()), true))); 
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
         curl_setopt($curl, CURLOPT_COOKIESESSION, true); 
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
         $response = curl_exec($curl); 
         $this->error = $response; // Only if there is problem 
         curl_close($curl); 
    
         // Write in logs 
         $date = new \DateTime('now'); 
         if (preg_match('#error#', $this->error)) { 
          $this->logger->error('Error on authentication success to deliver the OAuth token for ' . $event->getAuthenticationToken()->getUser() . ' the ' . $date->format('j/m/Y - H:i:s') . ' with message : ' . $this->error); 
         } 
    

    Heroku और मेरी लॉग से त्रुटि:

    heroku/router: at=error code=H12 desc="Request timeout" method=GET path="/app_dev.php/oauth/v2/token?grant_type=http://www.app/api/grants/api_key&client_id=261_1ws6mvgmbeisgcsw4wokwk8k400og88gs0csssg0gk0884080s&client_secret=1ghmf01c1a4kc448ssgwg8sw04840c4ww8k00gg4o0k8w04g4&api_key=7f5284ac5ec8b35527d3c16dafa52a89" host=app-max.herokuapp.com request_id=dc8960fd-d154-4e5d-bc2f-34d4f25b8070 fwd="46.51.146.244" dyno=web.1 connect=0ms service=30006ms status=503 bytes=0 
    app.ERROR: Une erreur est survenue lors de l'attribution du token OAuth de [email protected] le 25/11/2015 - 16:12:40 avec le message : <!DOCTYPE html>  <html>  <head>  <meta name="viewport" content="width=device-width, initial-scale=1">  <style type="text/css">   html, body, iframe { margin: 0; padding: 0; height: 100%; }   iframe { display: block; width: 100%; border: none; }  </style>  <title>Application Error</title>  </head>  <body>  <iframe src="//s3.amazonaws.com/heroku_pages/error.html">   <p>Application Error</p>  </iframe>  </body>  </html> [] [] 
    

    आपकी मदद के लिए धन्यवाद!

    EventListener

    $tokenController = new FOS\OAuthServerBundle\Controller\TokenController($this->oauth2); // $this->oauth2 is the @fos_oauth_server.server service 
    $credentials = $tokenController->tokenAction($request); 
    $response = $credentials->getContent(); 
    

    यह मेरा एपीआई में लॉग इन करने, cURL और वह URL जिसका टोकन देने का उपयोग कर whithout सिर्फ एक और उपाय है:

  • +1

    क्या आपने 'CURLOPT_TIMEOUT' सेट करने का प्रयास किया था? उदा।: Curl_setopt ($ curl, CURLOPT_TIMEOUT, 60); ' – scoolnico

    +0

    आपके उत्तर के लिए धन्यवाद लेकिन हाँ मैंने कोशिश की और यह –

    +0

    और 'USERAGENT' के बारे में क्या नहीं है? 'curl_setopt ($ curl, CURLOPT_USERAGENT, 'मोज़िला/5.0 (एक्स 11; यू; लिनक्स x86_64; एन-यूएस) ऐप्पलवेबकिट/537.36 (केएचटीएम, जैसे गीको) क्रोम/41.0.2225.0 सफारी/537.36'); – scoolnico

    उत्तर

    3

    मैं एक समाधान मिल गया।