Skip to content

Instantly share code, notes, and snippets.

@chrislewis
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislewis/4465cd864c8f35a71cfd to your computer and use it in GitHub Desktop.
Save chrislewis/4465cd864c8f35a71cfd to your computer and use it in GitHub Desktop.
<?php
/*
* This is a simple example of using PHP's OAuth extension to send a message
* to another member. It assumes you have already recieved the necessary
* authorization from the user and stored the token for reuse.
* See https://gist.github.com/chrislewis/7a1286924a93b369de86 for an
* example of how to fetch a valid token for a given member, with her
* authorization, using your consumer key and secret.
*
* chrisl@meetup.com
*/
/** Your oauth consumer key and secret, as created by Meetup when you register
a new consumer.
See: https://secure.meetup.com/meetup_api/oauth_consumers/ */
$consumer_key = YOUR_CONSUMER_KEY;
$consumer_secret = YOUR_CONSUMER_SECRET;
/** Once you have requested permission from a user and that user has authorized
your application, a 'verifier' is issued which you can then use to fetch an
access token. This can be stored by your application for reuse so users
don't have to repeat the authorization flow. Let's assume you have this
token (which consists of an oauth token and its secret) and assign them to
these variables. */
$oauth_token = YOUR_OAUTH_TOKEN;
$oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET;
/** Construct an OAuth client using your consumer key and secret. Note that this
uses PHP's OAuth extension; refer to its documentation for details:
http://php.net/manual/en/book.oauth.php. */
$oauth = new OAuth($consumer_key, $consumer_secret);
$oauth->setToken($oauth_token, $oauth_token_secret);
try {
$api_params = array(
'member_id' => MEMBER_ID, /* Provide the id of the member you wish
to message. */
'subject' => 'Hello via the Meetup API!',
'message' => 'Just saying hello :-).'
);
/* Dispatch a call to the message endpoint. Note that we must perform a POST,
as sepecified in the meetup API documentation:
http://www.meetup.com/meetup_api/docs/2/message/ */
$success = $oauth->fetch('https://api.meetup.com/2/message',
$api_params, OAUTH_HTTP_METHOD_POST);
if($success) {
/* The call succeeded. */
} else {
/* Something was wrong with the API call or an error may have occurred on
the server. Use methods on the $oauth object to get more details. */
}
} catch(OAuthException $E) {
/* Something was wrong with the oauth call itself; perhaps an invalid token
or secret. Use methods on the $E object to get more details. */
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment