# codef.io php로 토큰값 가져오기

- 주소: https://duotone.co.kr/entry/codefio-php%EB%A1%9C-%ED%86%A0%ED%81%B0%EA%B0%92-%EA%B0%80%EC%A0%B8%EC%98%A4%EA%B8%B0
- 글쓴이: 서기㏇
- 카테고리: 개발·프로그래밍
- 작성일: 2022-11-07
- 태그: codef, codef.io, JSON, php, token, 코드에프, 토큰

```

    $url = "https://oauth.codef.io/oauth/token?grant_type=client_credentials&scope=read";

    $clientId = "클라이언트ID";
    $clientSecret = "클라이언트시크릿키";

     $credentials  = base64_encode($clientId.":".$clientSecret);

    $headers = [];
    $headers[] = "Authorization: Basic {$credentials}";
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Cache-Control: no-cache';

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $response = curl_exec($ch);
    if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
    }
    curl_close($ch);

    $memo = json_decode($response,true);
    print_r($memo);
```

codef.io에 auth2.0을 사용하려면 먼저 토큰값을 가져와야 한다. 
이와 관련된 스크립트가 공개되어 있지 않아 작성해 놓는다.
