8000 Add README sections about app-only auth · codezninja/codebird-php@0977ff0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0977ff0

Browse files
committed
Add README sections about app-only auth
1 parent d277713 commit 0977ff0

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,23 @@ Some API methods also support authenticating on a per-application level.
7979
This is useful for getting data that are not directly related to a specific
8080
Twitter user, but generic to the Twitter ecosystem (such as ```search/tweets```).
8181

82-
**Codebird does not currently support application-only auth, but will soon.**
82+
To obtain an app-only bearer token, call the appropriate API:
83+
84+
```php
85+
$reply = $cb->oauth2_token();
86+
$bearer_token = $reply->access_token;
87+
```
88+
89+
I strongly recommend that you store the obtained bearer token in your database.
90+
There is no need to re-obtain the token with each page load, as it becomes invalid
91+
only when you call the ```oauth2/invalidate_token``` method.
92+
93+
If you already have your token, tell Codebird to use it:
94+
```php
95+
Codebird::setBearerToken('YOURBEARERTOKEN');
96+
```
97+
98+
For sending an API request with app-only auth, see the ‘Usage examples’ section.
8399

84100

85101
2. Usage examples
@@ -1 92F7 20,6 +136,17 @@ $params = array(
120136
$reply = $cb->statuses_updateWithMedia($params);
121137
```
122138

139+
### Requests with app-only auth
140+
141+
To send API requests without an access token for a user (app-only auth),
142+
add a second parameter to your method call, like this:
143+
144+
```php
145+
$reply = $cb->search_tweets('q=Twitter', true);
146+
```
147+
148+
Bear in mind that not all API methods support application-only auth.
149+
123150
3. Mapping API methods to Codebird function calls
124151
-------------------------------------------------
125152

0 commit comments

Comments
 (0)
0