Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:05:58+00:00 2026-06-17T07:05:58+00:00

I’m new at this, trying to hook up Box’s API v2. I successfully set

  • 0

I’m new at this, trying to hook up Box’s API v2. I successfully set up a PHP client library, which I found thanks to the link in the first paragraph on developers.box.com/auth. I’ve read Box’s walkthrough in full more than twice along with roughly 100,000 questions and replies here in regard to the matter. My problem occurs after the user redirects to Box’s authorization page, enters his credentials and clicks on “Allow.” The results vary according to my redirect_uri and the url of my login page where I’ve put my client_id and client_secret: 1) If my redirect_uri matches my https://mysite.com/login_with_box, the user redirects to that same url, obviously, which in turn sends the user back to Box’s authorization page; and 2) if my redirect_uri differs from https://mysite.com/login_with_box page, then the user successfully returns to my redirect_uri, the url of which includes the 30-second code. I know that I’m close to figuring this out but don’t know how to turn the code into a token in 30 seconds or less and use it to show the user’s folders, files, info or whatever else. Many thanks for your consideration. Here’s where I stand:

// mysite.com/client.php:

// ...

case 'Box':
    $this->oauth_version = '2.0';
    $this->request_token_url = '';
    $this->dialog_url = 'https://api.box.com/oauth2/authorize?client_id={CLIENT_ID}&response_type=code&redirect_uri={REDIRECT_URI}&state={STATE}';

    $this->append_state_to_redirect_uri = '';
    $this->access_token_url = 'https://api.box.com/oauth2/token';
    $this->authorization_header = true;
    $this->url_parameters = false;
break;

// ...

// mysite.com/login_with_box.php:

// ...

$client->client_id = '[my_client_id]';
$client->client_secret = '[my_client_secret]';

if(($success = $client->Initialize())) {
    if(($success = $client->Process())) {
        if(strlen($client->access_token)) {
            $success = $client->CallAPI(
                'https://api.box.com/2.0/users/me', 
                'GET', array(), array('FailOnAccessError'=>true), $user);
        }
    }
    $success = $client->Finalize($success);
}

// ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:06:00+00:00Added an answer on June 17, 2026 at 7:06 am

    I figured it out. The problem of course was entirely my fault. Here’s how I hooked up the Box API v2 with the PHP OAuth library reccommended by Box:

    1. Create an app on developers.box.com and set the required redirect_uri to something like https://mysite.com/oauth/login_with_box.php.

    2. Download the PHP OAuth library at www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html

    3. Add something like the following case to PHP OAuth library’s oauth_client.php.

      case 'Box':
          $this->oauth_version = '2.0';
          $this->request_token_url = '';
          $this->dialog_url = 'https://api.box.com/oauth2/authorize?response_type=code&client_id={CLIENT_ID}&state={STATE}';
          $this->append_state_to_redirect_uri = '';
          $this->access_token_url = 'https://api.box.com/oauth2/token';
          $this->authorization_header = true;
          $this->url_parameters = false;
      break;
      
    4. Create something like login_with_box.php and add it to PHP OAuth library. My login_with_box.php reads as follows.

      <?php  
      
      require('http.php');
      
      require('oauth_client.php');
      
      $client = new oauth_client_class;
      
      $client->server = 'Box';
      
      $client->redirect_uri = 'https://mysite.com/oauth/login_with_box.php';
      
      $client->client_id = 'xxxxxx_BOX_API_CLIENT_ID_xxxxxx';
      
      $client->client_secret = 'xxxxxx_BOX_API_CLIENT_SECRET_xxxxxx';
      
      if(strlen($client->client_id) == 0 || strlen($client->client_secret) == 0)
        die('You need an app to do that.');
      
      if(($success = $client->Initialize())) {
      
          if(($success = $client->Process())) {
      
              if(strlen($client->access_token)) {
      
              $success = $client->CallAPI(
      
                  'https://api.box.com/2.0/folders/0',
      
                  'GET', array('format'=>'json'), array('FailOnAccessError'=>true), $folder);
      
              }
      
          }
      
          $success = $client->Finalize($success);
      
      }
      
      if($client->exit)
      
          exit;
      
      if($success) { 
      
      ?>
      
      <!doctype html>
      <html>
      <head>
      <title>Box OAuth client results</title>
      </head>
      <body>
      <?php echo '<h1>You successfully logged in with Box</h1>'; echo '<pre>', HtmlSpecialChars(print_r($folder, 1)), '</pre>'; ?>
      
      </body>
      </html>
      
      <?php } else { ?>
      
      <!doctype html>
      <html>
      <head>
      <title>OAuth client error</title>
      </head>
      <body>
      <h1>OAuth client error</h1>
      <pre>Error: <?php echo HtmlSpecialChars($client->error); ?></pre>
      </body>
      </html>
      
      <?php } ?>
      

    I hope this helps somebody.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.