social_content_instagram.admin.inc in Social Content 7
Social Content administration area for Instagram.
Provides menu callbacks for the administration area of Instagram.
File
modules/instagram/social_content_instagram.admin.incView source
<?php
/**
* @file
* Social Content administration area for Instagram.
*
* Provides menu callbacks for the administration area of Instagram.
*/
function social_content_instagram_token_generator_form($form, $form_state, $social_content_type) {
$settings = social_content_get_settings($social_content_type);
$redirect_url = url(current_path(), array(
'absolute' => TRUE,
));
$form['description'] = array(
'#markup' => '<p>' . t('Use this form to generate the Instagram access token.') . '</p>' . '<p>' . t('You can obtain your client id and secret by visiting !instagram_url', array(
'!instagram_url' => SOCIAL_CONTENT_INSTAGRAM_CLIENT_DETAILS_URL,
)) . '</p>' . '<p>' . t('Please ensure that you have the following redirect uri in your account settings:') . '</p>' . ' <strong>' . $redirect_url . '</strong>',
);
if (isset($_GET['code'])) {
$fields = array(
'client_id' => $settings['client_id'],
'client_secret' => $settings['client_secret'],
'grant_type' => 'authorization_code',
'redirect_uri' => $redirect_url,
'code' => $_GET['code'],
);
$result = drupal_http_request(SOCIAL_CONTENT_INSTAGRAM_ACCESS_TOKEN_URL, array(
'method' => 'post',
'data' => drupal_http_build_query($fields),
));
$data = json_decode($result->data);
if ($result->code != 200) {
drupal_set_message(t('Error: !error', array(
'!error' => $result->data,
)), 'error');
}
else {
drupal_set_message(t('New access token is !access_token', array(
'!access_token' => $data->access_token,
)));
}
}
$form['id'] = array(
'#type' => 'textfield',
'#title' => t('Client ID'),
'#default_value' => $settings['client_id'],
);
$form['secret'] = array(
'#type' => 'textfield',
'#title' => t('Client Secret'),
'#default_value' => $settings['client_secret'],
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Get access token'),
);
return $form;
}
function social_content_instagram_token_generator_form_submit($form, $form_state) {
$query = array(
'client_id' => $form_state['values']['client_id'],
'redirect_uri' => $redirect_uri,
'response_type' => 'code',
);
drupal_goto(SOCIAL_CONTENT_INSTAGRAM_AUTHORIZE_URL, array(
'query' => $query,
'external' => TRUE,
));
}
Functions
Name![]() |
Description |
---|---|
social_content_instagram_token_generator_form | @file Social Content administration area for Instagram. |
social_content_instagram_token_generator_form_submit |