Showing posts with label using. Show all posts
Showing posts with label using. Show all posts

Tuesday, March 10, 2015

Tips on using the APIs Discovery Service

Our newest set of APIs - Tasks, Calendar v3, Google+ to name a few - are supported by the Google APIs Discovery Service. The Google APIs Discovery service offers an interface that allows developers to programmatically get API metadata such as:

  • A directory of supported APIs.
  • A list of API resource schemas based on JSON Schema.
  • A list of API methods and parameters for each method and their inline documentation.
  • A list of available OAuth 2.0 scopes.

The APIs Discovery Service is especially useful when building developer tools, as you can use it to automatically generate certain features. For instance we are using the APIs Discovery Service in our client libraries and in our APIs Explorer but also to generate some of our online API reference.

Because the APIs Discovery Service is itself an API, you can use features such as partial response which is a way to get only the information you need. Let’s look at some of the useful information that is available using the APIs Discovery Service and the partial response feature.

List the supported APIs

You can get the list of all the APIs that are supported by the discovery service by sending a GET request to the following endpoint:


https://www.googleapis.com/discovery/v1/apis?fields=items(title,discoveryLink)

Which will return a JSON feed that looks like this:


{
"items": [

{
"title": "Google+ API",
"discoveryLink": "./apis/plus/v1/rest"
},
{
"title": "Tasks API",
"discoveryLink": "./apis/tasks/v1/rest"
},
{
"title": "Calendar API",
"discoveryLink": "./apis/calendar/v3/rest"
},

]
}

Using the discoveryLink attribute in the resources part of the feed above you can access the discovery document of each API. This is where a lot of useful information about the API can be accessed.

Get the OAuth 2.0 scopes of an API

Using the API-specific endpoint you can easily get the OAuth 2.0 scopes available for that API. For example, here is how to get the scopes of the Google Tasks API:


https://www.googleapis.com/discovery/v1/apis/tasks/v1/rest?fields=auth(oauth2(scopes))

This method returns the JSON output shown below, which indicates that https://www.googleapis.com/auth/tasks and https://www.googleapis.com/auth/tasks.readonly are the two scopes associated with the Tasks API.


{
"auth": {
"oauth2": {
"scopes": {
"https://www.googleapis.com/auth/tasks": {
"description": "Manage your tasks"
},
"https://www.googleapis.com/auth/tasks.readonly": {
"description": "View your tasks"
}
}
}
}
}

Using requests of this type you could detect which APIs do not support OAuth 2.0. For example, the Translate API does not support OAuth 2.0, as it does not provide access to OAuth protected resources such as user data. Because of this, a GET request to the following endpoint:


https://www.googleapis.com/discovery/v1/apis/translate/v2/rest?fields=auth(oauth2(scopes))

Returns:


{}

Getting scopes required for an API’s endpoints and methods

Using the API-specific endpoints again, you can get the lists of operations and API endpoints, along with the scopes required to perform those operations. Here is an example querying that information for the Google Tasks API:


https://www.googleapis.com/discovery/v1/apis/tasks/v1/rest?fields=resources/*/methods(*(path,scopes,httpMethod))

Which returns:


{
"resources": {
"tasklists": {
"methods": {
"get": {
"path": "users/@me/lists/{tasklist}",
"httpMethod": "GET",
"scopes": [
"https://www.googleapis.com/auth/tasks",
"https://www.googleapis.com/auth/tasks.readonly"
]
},
"insert": {
"path": "users/@me/lists",
"httpMethod": "POST",
"scopes": [
"https://www.googleapis.com/auth/tasks"
]
},

}
},
"tasks": {

}
}
}

This tells you that to perform a POST request to the users/@me/lists endpoint (to insert a new task) you need to have been authorized with the scope https://www.googleapis.com/auth/tasks and that to be able to do a GET request to the users/@me/lists/{tasklist} endpoint you need to have been authorized with either of the two Google Tasks scopes.

You could use this to do some automatic discovery of the scopes you need to authorize to perform all the operations that your applications does.

You could also use this information to detect which operations and which endpoints you can access given a specific authorization token ( OAuth 2.0, OAuth 1.0 or Authsub token). First, use either the Authsub Token Info service or the OAuth 2.0 Token Info Service to determine which scopes your token has access to (see below); and then deduct from the feed above which endpoints and operations requires access to these scopes.

                        
[Access Token] -----(Token Info)----> [Scopes] -----(APIs Discovery)----> [Operations/API Endpoints]

Example of using the OAuth 2.0 Token Info service:

Request:


GET /oauth2/v1/tokeninfo?access_token= HTTP/1.1
Host: www.googleapis.com

Response:


HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8


{
"issued_to": "1234567890.apps.googleusercontent.com",
"audience": "1234567890.apps.googleusercontent.com",
"scope": "https://www.google.com/m8/feeds/
https://www.google.com/calendar/feeds/",
"expires_in": 1038
}

There is a lot more you can do with the APIs Discovery Service so I invite you to have a deeper look at the documentation to find out more.


Nicolas Garnier profile | twitter | events

Nicolas joined Google’s Developer Relations in 2008. Since then hes worked on commerce oriented products such as Google Checkout and Google Base. Currently, he is working on Google Apps with a focus on the Google Calendar API, the Google Contacts API, and the Tasks API. Before joining Google, Nicolas worked at Airbus and at the French Space Agency where he built web applications for scientific researchers.

Read more »

Wednesday, February 18, 2015

How to Swap Two Numbers Without Using Temporary Variable or Arithmetic Operators


You have done swapping of two numbers using temporary variable or by using arithmetic operators. It can be done in following way.

Lets take two numbers a=5 and b=7.

Using Temporary Variable

temp=a;            //temp becomes 5
a=b;                 //a becomes 7
b=temp;            //b becomes 5

Also Read: C++ program to swap two numbers using pointers
Also Read: C++ program to swap two numbers using class

Using Arithmetic Operators

a=a+b;              //a becomes 12
b=a-b;              //b becomes 5
a=a-b;               //a becomes 7

or

a=a*b;              //a becomes 35
b=a/b;              //b becomes 5
a=a/b;               //a becomes 7


In this article I am sharing another method, may be you are already familiar with it. Swapping of two numbers can also be done by using bitwise XOR operator i.e. ^. The XOR of two numbers a and b returns a number which has all the bits as 1 wherever bits of a and b differ. If bits are same then resultant bit will be 0.

For example binary of 5 is 0101 and 7 is 0111. If you do XOR of 5 and 7 then result will be 0010. A c program is given below that uses this concept to swap values of two numbers.

Also Read: C++ program to swap two numbers using macros
Also Read: C++ Templates: Program to Swap Two Numbers Using Function Template

#include <stdio.h>

int main()
{
  int a=5,b=7;

  a=a^b;  // a becomes 2 (0010)
  b=a^b;  // b becomes 5 (0101)
  a=a^b;  // a becomes 7 (0111)

  printf("After Swapping: a=%d,b=%d",a,b);

  return 0;
}

How to Swap Two Numbers Without Using Temporary Variable or Arithmetic Operators?

If you have any doubts or know any other method to swap values of two numbers then mention it in comment section.

Happy Coding!! :) :)

Source: http://www.geeksforgeeks.org/swap-two-numbers-without-using-temporary-variable/
Read more »

Monday, February 16, 2015

C program to find cube of a number using macros


C++ program to find cube of a number using macros

Also Read: C++ program to swap two numbers using macros
Also Read: C++ Program to find cube of a number using function

#include<iostream.h>
#include<conio.h>

#define CUBE(x) (x*x*x)

void main()
{
clrscr();
int n,cube;
cout<<"Enter a number:";
cin>>n;

cube=CUBE(n);
cout<<"Cube="<<cube;
getch();
}
Read more »

Saturday, February 14, 2015

C program to print numbers from 1 to 10 using for loop


#include<stdio.h>
#include<conio.h>

void main()
{
int i;
clrscr(); //to clear the screen

for(i=1;i<=10;++i)
{
printf("%d",i);
printf("
");

}

getch(); //to stop the screen
}
Read more »

Friday, February 13, 2015

C Program to sort an Array by using Bubble sort

C++ Program to sort an Array by using Bubble sort

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int a[50],n,i,j,temp;
cout<<"Enter the size of array: ";
cin>>n;
cout<<"Enter the array elements: ";

for(i=0;i<n;++i)
cin>>a[i];

for(i=0;i<n;++i)
for(j=0;j<(n-i);++j)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}

cout<<"Array after bubble sort: ";
for(i=0;i<n;++i)
cout<<a[i]<<" ";
getch();
}
Read more »

Wednesday, February 11, 2015

C C Program for Fibonacci Series Using Recursion

Series 0, 1, 1, 2, 3, 5, 8, 13, 21 . . . . . . . is a Fibonacci series. In Fibonacci series, each term is the sum of the two preceding terms. The C and C++ program for Fibonacci series is given below.

C Program


#include<stdio.h>

int fibonacci(int n)
{
if((n==1)||(n==0))
{
return(n);
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}

int main()
{
int n,i=0;
printf("Input the number of terms for Fibonacci Series:");
scanf("%d",&n);
printf("
Fibonnaci Series is as follows
");
while(i<n)
{
printf("%d ",fibonacci(i));
i++;
}

return 0;
}

C++ Program


#include<iostream>

using namespace std;

int fibonacci(int n)
{
if((n==1)||(n==0))
{
return(n);
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}

int main()
{
int n,i=0;
cout<<"Input the number of terms for Fibonacci Series:";
cin>>n;
cout<<"
Fibonnaci Series is as follows
";

while(i<n)
{
cout<<" "<<fibonacci(i);
i++;
}

return 0;
}

C/C++ Program for Fibonacci Series Using Recursion
Read more »

Tuesday, February 10, 2015

Simple program to create a circular loading bar using graphics


Simple program to create a circular loading bar using graphics

#include<graphics.h>
#include<dos.h>

void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"c:\turboc3\bgi");
for(i=0;i<=360;++i)
{
circle(300,200,80);
pieslice(300,200,0,i,80);
outtextxy(200,320,"Loading....Please Wait!");
delay(20);
}
closegraph();
}
Read more »

Wednesday, February 4, 2015

How To Download Firefox Without Using Internet Explorer


 
 
Internet Expolere-Hater Often Say That The Only GooD Use 4 Internet Explorer is Downloading Firefox or Chrome. But if You Really Dont like IE, You Can Use Windows Built-in FTP Support To Download and Install Firefox Without Ever Opening IE. Sure, You Could Just Open Internet Explorer and Download Firefox Frrom Mozilla website. But Where The Geeky Fun in That? This Trick is About Firefox Beacuse Mazilla Provides an FTP Server, While GooGle Does Not Seem to Downloading Firefox Without Using Internet Explorer May Also Come in Handly if Internet Explorer is Crashing ans is not Working Properly on Your System.


Graphical Method With Windows Explorere:

    To Access Mozilaa FTP Server in Windows Explorer, Type ftp://mozilla.org into Explorer Address Bar and Press Enter.
 

Navigate to the following Folder.

pub/firefox/releases/latest/win32/en-US/
 
You Can Also Just Enter The Following Address in Windows Explorer to Go Directly To The Appropriate Folder on Mozilla FTP Server.

ftp://ftp.mozilla.org/pub/firefox/releases/latest/win32/en-US/


Now Copy The Firefox setup.exe File To Your Computer, You Can Drag & Drop It, Use The Copy to Folder Option in Its Right-Click Menu, or Do a Copy and Paste.


Window Explorer Will Download The Firefox Installer To Your Computer, No IE Involved.




You Can Then Launch The Fire Steup Application to Install Fiefox.




Command Line Method With Command Prompt:

      If The Above Trick Was Not Geekly Enough For You, You Can also Download Firefox Using the ftp Utility in The Windows Command Prompt. Launch a Command Prompt Window From The Start Menu and Type The Following Command to Connect To Nozilla FTP Server.. 

fttp ftp.mozilla.org

Type Anonymous at the Login Prompt, Then Leave The Password Field Balnk & Press Enter



Use The Following Command to Change to The Directory Containing The Lates Release of Firefox:

cd pub/mozilla.org/firfox/releases/latest/win32/en-USg

Then, Run The Following Command to See a List of The Files in The Diresctory:

Is

Use The Get Command to Download The Latest Firefox Installer to Your Hard Driver:

get "Firefox Setup 15.0.1.exe"

Replace the File Name in The Above Command with the Name of The Current Version, This is Displayed Beneath Is Command.
 

The Download Firefox Setup.exe file Will Appear in Your User Folder ar C:UsersNAME.
 

You Can Also Use Windows Explorer and the ftp Command to Connect to Other FTP Servers You Have Access to if You Have Upload Access to an FTP Server, You Can Use These Tools to Upload Files- You Dont Necessarily Need a Third-Party FTP Program.
Read more »