Function to send a message:
const TOKEN = '99999999:AAAAAAAJjZ_T6hAAAAAAAAAAAAAAA';
const URL = 'https://api.telegram.org/bot'.TOKEN.'/';
function sendGetRequest($method,$params=null){
if($params){
$url = URL.$method.'?'.http_build_query($params);
}else{
$url = URL.$method;
}
return json_decode(file_get_contents($url), JSON_OBJECT_AS_ARRAY);
}
Function call:
$un_ban_params = [
'chat_id'=> $chat_id,
'user_id'=> $user_id*1,
];
sendGetRequest( 'unbanChatMember', $un_ban_params);
The call returns null.
Accordingly, the link to return to the group does not appear.
The answer is found. "unbanChatMember" is only valid in supergroups and channels. For a simple group, this method does not work.
Related
I am new in PHP and working to modify one API. Its built with Laravel Framework. I have API function like below in my controller.
public function DeleteOneMail(Request $request)
{
$uid = $request->uid;
if (\Request::is('api/*')) {
if ($request->has('key')) {
if (in_array($request->input('key'), explode(',', env('API_KEY')))) {
if ($uid == '') {
return response()->make('Please Enter UID', 401);
} else {
$client = Client::account('default');
$client->connect();
$inbox = $client->getFolder('INBOX');
$message = $inbox->getMessage($uid);
if ($message) {
return response(['success' => 1], 200);
} else {
return response(['success' => 0, 'message' => 'No Data Found'], 200);
}
}
} else {
return response()->make('Unauthorized Access. Please enter correct API Key', 401);
}
} else {
return response()->make('Unauthorized Access. Please enter correct API Key', 401);
}
}
}
I am calling API like below
https://example.com/api/delete-one-mail?key=2221212&uid=214
Its working fine without any issue. Now I want pass multiple uid with request and so I can process that uid one by one with my api function. I am not getting idea how I can pass arrary and process it. Let me know if any expert can help me for solve my puzzle. Thanks!
Your can pass an array like this
https://example.com/api/delete-one-mail?key=2221212&uid[]=214&uid[]=111&uid[]=222
$request->uid should be an array but you can make sure (if anyone use the old url with ony one uid) by doing
$uids = Arr::wrap($request->uid);
If you want to send an array by GET request just use []
https://example.com/api/delete-one-mail?key=2221212&uid[]=1&uid[]=2
In your controller you will get an array
$uid = $request->uid;
dd($uid);
As a result you will get
[1, 2]
I want to get all my data or select with by id, but something is wrong. When I try with route, not work. If i try without route, the select by ID work, and without id have "Missing argument..."
mysite.com/ws/v1/article - Return all my data (ok) but also a "Missing argument for Articles".
mysite.com/ws/v1/article/6 (6 = id example) Return "The page is not found".
Routes
$route['ws/v1/article'] = "api/articles/getArticle";
Controller
public function getArticle_get($id)
{
header("Access-Control-Allow-Origin: *");
// Load Authorization Token Library
$this->load->library('Authorization_Token');
/**
* User Token Validation
*/
$is_valid_token = $this->authorization_token->validateToken();
if (!empty($is_valid_token) AND $is_valid_token['status'] === TRUE)
{
if (empty($id)){
$data = $this->db->get("ga845_clientes")->result();
}else{
$data = $this->db->get_where("ga845_clientes", ['id' => $id])->row_array();
}
$this->response($data, REST_Controller::HTTP_OK);
} else {
$this->response(['status' => FALSE, 'message' => $is_valid_token['message'] ], REST_Controller::HTTP_NOT_FOUND);
}
}
This is how you pass the parameters in your api.
mysite.com/ws/v1/article/$6
To make your parameter optional,
$route['ws/v1/article/?(:id)?'] = "api/articles/getArticle/$1";
Is there is any way to retrieve users email address. I am using hybrid auth. Login works no email address obtained only got access userid , display name & display picture.
Is there any method to get access to email address of user,
Everything is working fine except . The response gives a blank email
class Yahoo extends OAuth2
{
protected $scope = 'sdct-r';
protected $apiBaseUrl = 'https://social.yahooapis.com/v1/';
protected $authorizeUrl = 'https://api.login.yahoo.com/oauth2/request_auth';
protected $accessTokenUrl = 'https://api.login.yahoo.com/oauth2/get_token';
protected $apiDocumentation = 'https://developer.yahoo.com/oauth2/guide/';
protected $userId = null;
protected function initialize()
{
parent::initialize();
$this->tokenExchangeHeaders = [
'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) ]; }
protected function getCurrentUserId()
{
if ($this->userId) {
return $this->userId;
}
$response = $this->apiRequest('me/guid', 'GET', [ 'format' => 'json']);
$data = new Data\Collection($response);
if (! $data->filter('guid')->exists('value')) {
throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
}
return $this->userId = $data->filter('guid')->get('value');
}
public function getUserProfile()
{
// Retrieve current user guid if needed
$this->getCurrentUserId();
$response = $this->apiRequest('user/' . $this->userId . '/profile', 'GET', [ 'format' => 'json']);
$data = new Data\Collection($response);
if (! $data->exists('profile')) {
throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
}
$userProfile = new User\Profile();
$data = $data->filter('profile');
$userProfile->identifier = $data->get('guid');
$userProfile->firstName = $data->get('givenName');
$userProfile->lastName = $data->get('familyName');
$userProfile->displayName = $data->get('nickname');
$userProfile->photoURL = $data->filter('image')->get('imageUrl');
$userProfile->profileURL = $data->get('profileUrl');
$userProfile->language = $data->get('lang');
$userProfile->address = $data->get('location');
if ('F' == $data->get('gender')) {
$userProfile->gender = 'female';
} elseif ('M' == $data->get('gender')) {
$userProfile->gender = 'male';
}
// I ain't getting no emails on my tests. go figures..
foreach ($data->filter('emails')->toArray() as $item) {
if ($item->primary) {
$userProfile->email = $item->handle;
$userProfile->emailVerified = $item->handle;
}
}
return $userProfile;
}
}
from the Yahoo guide:
The extended profile scope sdpp-w, in addition to the Claims given
above, also returns the following Claims:
email - the email ID of the user
email_verified - the Boolean flag letting Clients know if the given email address has been verified by Yahoo.
Please upgrade Hybridauth to 3.0-rc.10 which is fixed that issue for Yahoo provider.
See original PR with fix: https://github.com/hybridauth/hybridauth/pull/986
This is my code:
public function getLists(Request $request)
{
$user = $request->user()->id;
$apikey = DB::table('apikey')->where('api_key', '=', $user);
if($apikey){
$mc = new MailChimp($apikey);
$mailchimp_ping = $mc->get('lists',['fields' =>
'lists.id,lists.name']);
return Response::json($mailchimp_ping, 200);
}
else
{
$errorResponse = [
'message' => 'Lists not found!',
'error' => '401'
];
return Response::json( $errorResponse);
}
}
I am trying to get mailchimp list based on logged in user id where i am doing wrong? is my where clause expects something else?
Any help would be highly appreciated!
Use the value() method to execute the query and get the key. For example, if a column with key is called apikey:
$apikey = DB::table('apikey')->where('api_key', $user)->value('apikey');
In my case this error came up when changed this:
Route::view('/report', '/main_pages/orders_parts/report')->name('guzorishi_order_1');
to
Route::get('/report/{order_id}', function ($order_id) {... })->name('guzorishi_order_1');
but forgot Route::view one
rename to Route::get
I want to pull channel information based on a username or channel id. This information is derived from the URL used to view that channel.
EX: https://www.youtube.com/user/csga5000, or, https://www.youtube.com/channel/some-channel-id
I have this code:
$this->load->library('APIs/YouTube');
echo "[";
echo json_encode($this->youtube->getId('channel/UCkklJA9WbtJM5-g21xHI3yA'),false);
echo "\n]";
The function called is:
public function getId($url) {
$id = explode('/', $url);
echo json_encode($id).',';
//User's channel
if ($id[0] === 'user') {
$response = $this->youtube->channels->listChannels('id,snippet',array(
'forUsername' => $id[1]
));
}
//Channel id
else {
$response = $this->youtube->channels->listChannels('id,snippet',array(
'id' => $id[1],
'maxResults' => 2
));
}
return $response;
}
Here is the construct function for the youtube class:
public function __construct()
{
$this->client = new Google_Client();
$this->client->setDeveloperKey($this->api_key);
$this->client->setClientId($this->client_id);
$this->client->setClientSecret($this->client_secret);
$this->client->setScopes(array(
Google_Service_Oauth2::PLUS_LOGIN,
Google_Service_Oauth2::PLUS_ME,
Google_Service_Oauth2::USERINFO_EMAIL,
Google_Service_Oauth2::USERINFO_PROFILE,
Google_Service_YouTube::YOUTUBE
));
$ci =& get_instance();
$this->client->setRedirectUri($ci->config->item('base_url').'auth/youtube/');
$this->oauth = new Google_Service_Oauth2($this->client);
$this->youtube = new Google_Service_YouTube($this->client);
}
Calling the function with 'user/csga5000' doesn't work either
The results printed are:
[
[
"channel",
"UCkklJA9WbtJM5-g21xHI3yA"
],
{
"etag":"\"IHLB7Mi__JPvvG2zLQWAg8l36UU\/KcPrlZVHCJ9bAKurpGOj1BBEH6g\"",
"eventId":null,
"kind":"youtube#channelListResponse",
"nextPageToken":null,
"prevPageToken":null,
"visitorId":null
}
]
I just want results like this:
https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet&id=UCkklJA9WbtJM5-g21xHI3yA&key={YOUR_API_KEY}
or
https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet&forUsername=csga5000&key={YOUR_API_KEY}
Which you can test here:
https://developers.google.com/youtube/v3/docs/channels/list#try-it
With forUsername csga5000 or id UCkklJA9WbtJM5-g21xHI3yA
All the examples I found used "mine => true" and oauth to load this data, so nothing on google, or stack overflow seemed helpful.
I was just missing something silly, I'd been super confused by the response.
I needed the line:
$response->getItems();