www.webdeveloper.com
Results 1 to 5 of 5

Thread: catch a curl error

  1. #1
    Join Date
    Jan 2008
    Posts
    273

    catch a curl error

    Hi All

    I have the following code

    Code:
    <?php
    
            $ch = curl_init( 'https://graph.facebook.com/1234567890/feed/' ) ;
    
            curl_setopt($ch, CURLOPT_POSTFIELDS, 'access_token=sdfsdfsdfsf323erfaesg&link=http://example.com' ) ;
    
            $content = curl_exec( $ch );
    
    ?>
    If you run it it print the following to your screen:
    Code:
    {"error":{"type":"OAuthException","message":"Invalid OAuth access token."}}
    In my situation I don't want this to be printed to the screen I want to catch it in my program and respond to it

    Any suggestions how to do this ?

    UPDATE: I just noticed curl also writes stuff to STDOU when no errors occurred
    Last edited by jeanluca; 07-08-2010 at 08:12 AM.

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    It isn't curl giving you the error, that is the data returned from the request. You get the same if you make the request in a browser:

    https://graph.facebook.com/123456789...://example.com

    Edit: oops I think I misunderstood your issue. You need to set the CURLOPT_RETURNTRANSFER option via curl_setopt before calling curl_exec.
    Last edited by Mindzai; 07-08-2010 at 09:41 AM.
    The first rule of Tautology Club is the first rule of Tautology Club.

  3. #3
    Join Date
    Jan 2008
    Posts
    273
    true, but I need to parse this to know if everything went well.
    I noticed you can redirect the output to file, but thats not what I want, I need it in my program. Any suggestions ?

  4. #4
    Join Date
    Nov 2008
    Posts
    2,477
    See my edit above, I misunderstood your problem initially
    The first rule of Tautology Club is the first rule of Tautology Club.

  5. #5
    Join Date
    Jan 2008
    Posts
    273
    thats it! thnx a lot!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles